From e50f43416b5a8b522695d8cbb7cf31112d51e8f2 Mon Sep 17 00:00:00 2001 From: axel Date: Fri, 23 Feb 2007 07:45:55 +1000 Subject: [PATCH] Add missing file for vi completions that is needed to complete files selectively based on mime types. Also use it to improve emacs completions, in order to balance my GNU karma. darcs-hash:20070222214555-ac50b-60aa6a3e4cea77451c51d40d2a574d145f3de4fe.gz --- share/completions/emacs.fish | 4 +++ share/functions/__fish_complete_mime.fish | 30 +++++++++++++++++++++++ share/functions/__fish_complete_vi.fish | 2 +- 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 share/functions/__fish_complete_mime.fish diff --git a/share/completions/emacs.fish b/share/completions/emacs.fish index a6001323b..d8de28b39 100644 --- a/share/completions/emacs.fish +++ b/share/completions/emacs.fish @@ -1,6 +1,10 @@ # # These completions are uncomplete # + +# Primarily complete text files +complete -c emacs -x -a "(__fish_complete_mime 'text/*')" + complete -c emacs -s q --description "Do not load init files" complete -c emacs -s u --description "Load users init file" -xa "(__fish_complete_users)" complete -c emacs -s t --description "Use file as terminal" -r diff --git a/share/functions/__fish_complete_mime.fish b/share/functions/__fish_complete_mime.fish new file mode 100644 index 000000000..76c4e7165 --- /dev/null +++ b/share/functions/__fish_complete_mime.fish @@ -0,0 +1,30 @@ + +function __fish_complete_mime -d "Complete using text files" + # Find all possible file completions + set -l all + set -l comp (commandline -ct) + set -l base (echo $comp | sed -e 's/\.[a-zA-Z0-9]*$//') + set -l mimetype $argv[1] + eval "set all $base*" + + # Select text files only + set -l files (__fish_filter_mime $mimetype $all) + + # Get descriptions for files + set desc (mimedb -d $files) + + # Format completions and descriptions + set -l res + for i in (seq (count $files)) + set res $res $files[$i]\t$desc[$i] + end + + if test $res[1] + printf "%s\n" $res + end + + # Also do directory completion, since there might be files + # with the correct suffix in a subdirectory + __fish_complete_directories $comp +end + diff --git a/share/functions/__fish_complete_vi.fish b/share/functions/__fish_complete_vi.fish index c5fa20ff2..39a71ac38 100644 --- a/share/functions/__fish_complete_vi.fish +++ b/share/functions/__fish_complete_vi.fish @@ -7,7 +7,7 @@ function __fish_complete_vi -d "Compleletions for vi and its aliases" set -l cmds -c $argv - complete $cmds -x -a "(__fish_complete_text)" + complete $cmds -x -a "(__fish_complete_mime 'text/*')" # vim if test -n "$is_vim"