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"