diff --git a/share/functions/__fish_complete_directories.fish b/share/functions/__fish_complete_directories.fish index 35a82e92a..158f0eb1b 100644 --- a/share/functions/__fish_complete_directories.fish +++ b/share/functions/__fish_complete_directories.fish @@ -2,20 +2,13 @@ # Find directories that complete $argv[1], output them as completions # with description $argv[2] if defined, otherwise use 'Directory' # - -function __fish_complete_directories -d "Complete using directories" --argument comp - - set desc (_ Directory) - - if test (count $argv) -gt 1 - set desc $argv[2] +function __fish_complete_directories -d "Complete directory prefixes" --argument comp desc + if not set -q desc[1] + set desc (_ Directory) end - eval "set dirs "$comp"*/" - - if test $dirs[1] + set -l dirs $comp*/ + if set -q dirs[1] printf "%s\t$desc\n" $dirs end - end - diff --git a/tests/__fish_complete_directories.err b/tests/__fish_complete_directories.err new file mode 100644 index 000000000..e69de29bb diff --git a/tests/__fish_complete_directories.in b/tests/__fish_complete_directories.in new file mode 100644 index 000000000..4a98fce17 --- /dev/null +++ b/tests/__fish_complete_directories.in @@ -0,0 +1,19 @@ +cd .. +mkdir test/data/abc +mkdir test/data/abcd +touch test/data/af +touch test/data/abcdf +mkdir test/data/xy +mkdir test/data/xyz +touch test/data/xyf +touch test/data/xyzf +echo \# __fish_complete_directories test/z +__fish_complete_directories test/z +echo \# __fish_complete_directories test/d +__fish_complete_directories test/d +echo \# __fish_complete_directories test/data +__fish_complete_directories test/data +echo \# __fish_complete_directories test/data/ +__fish_complete_directories test/data/ +echo \# __fish_complete_directories test/data/abc +__fish_complete_directories test/data/abc 'abc dirs' diff --git a/tests/__fish_complete_directories.out b/tests/__fish_complete_directories.out new file mode 100644 index 000000000..a098be2bb --- /dev/null +++ b/tests/__fish_complete_directories.out @@ -0,0 +1,14 @@ +# __fish_complete_directories test/z +# __fish_complete_directories test/d +test/data/ Directory +# __fish_complete_directories test/data +test/data/ Directory +# __fish_complete_directories test/data/ +test/data/abc/ Directory +test/data/abcd/ Directory +test/data/fish/ Directory +test/data/xy/ Directory +test/data/xyz/ Directory +# __fish_complete_directories test/data/abc +test/data/abc/ abc dirs +test/data/abcd/ abc dirs