__fish_complete_directories: Use an empty command as the dummy

Fixes #9574

(cherry picked from commit 200095998a)
This commit is contained in:
Fabian Boehm 2023-02-14 17:06:11 +01:00 committed by David Adam
parent 2419f39cfd
commit 17332226e4
2 changed files with 8 additions and 3 deletions

View File

@ -12,12 +12,13 @@ function __fish_complete_directories -d "Complete directory prefixes" --argument
set comp (commandline -ct)
end
# HACK: We call into the file completions by using a non-existent command.
# HACK: We call into the file completions by using an empty command
# If we used e.g. `ls`, we'd run the risk of completing its options or another kind of argument.
# But since we default to file completions, if something doesn't have another completion...
set -l dirs (complete -C"nonexistentcommandooheehoohaahaahdingdongwallawallabingbang $comp" | string match -r '.*/$')
# (really this should have an actual complete option)
set -l dirs (complete -C"'' $comp" | string match -r '.*/$')
if set -q dirs[1]
printf "%s\t$desc\n" $dirs
printf "%s\n" $dirs\t"$desc"
end
end

View File

@ -46,6 +46,10 @@ complete -c t -l fileoption -rF
complete -C't --fileoption ' | string match test.fish
# CHECK: test.fish
# See that an empty command gets files
complete -C'"" t' | string match test.fish
# CHECK: test.fish
# Make sure bare `complete` is reasonable,
complete -p '/complete test/beta1' -d 'desc, desc' -sZ
complete -c 'complete test beta2' -r -d 'desc \' desc2 [' -a 'foo bar'