From 200095998a71e1ee60e61d1840edc98413ecfd14 Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Tue, 14 Feb 2023 17:06:11 +0100 Subject: [PATCH] __fish_complete_directories: Use an empty command as the dummy Fixes #9574 --- share/functions/__fish_complete_directories.fish | 7 ++++--- tests/checks/complete.fish | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/share/functions/__fish_complete_directories.fish b/share/functions/__fish_complete_directories.fish index a4db0ec22..31eaf23e1 100644 --- a/share/functions/__fish_complete_directories.fish +++ b/share/functions/__fish_complete_directories.fish @@ -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 diff --git a/tests/checks/complete.fish b/tests/checks/complete.fish index 2f13b3fcf..7fabf2c45 100644 --- a/tests/checks/complete.fish +++ b/tests/checks/complete.fish @@ -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'