mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-12 04:58:57 +00:00
improve __fish_complete_directories
function
Reviewing a PR for a completion script caused me to look at the implementation for the `__fish_complete_directories` function. Which in turn lead me to create this change to improve its implementation and add unit tests for the function.
This commit is contained in:
parent
2a2ccea24e
commit
da09a915f2
4 changed files with 38 additions and 12 deletions
|
@ -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
|
||||
|
||||
|
|
0
tests/__fish_complete_directories.err
Normal file
0
tests/__fish_complete_directories.err
Normal file
19
tests/__fish_complete_directories.in
Normal file
19
tests/__fish_complete_directories.in
Normal file
|
@ -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'
|
14
tests/__fish_complete_directories.out
Normal file
14
tests/__fish_complete_directories.out
Normal file
|
@ -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
|
Loading…
Reference in a new issue