diff --git a/share/functions/__fish_complete_directories.fish b/share/functions/__fish_complete_directories.fish index 31eaf23e1..ce844d5c6 100644 --- a/share/functions/__fish_complete_directories.fish +++ b/share/functions/__fish_complete_directories.fish @@ -9,7 +9,11 @@ function __fish_complete_directories -d "Complete directory prefixes" --argument end if not set -q comp[1] - set comp (commandline -ct) + # No token given, so we use the current commandline token. + # If we have a --name=val option, we need to remove it, + # or the complete -C below would keep it, and then whatever complete + # called us would add it again (assuming it's in the current token) + set comp (commandline -ct | string replace -r -- '^-[^=]*=' '' $comp) end # HACK: We call into the file completions by using an empty command diff --git a/tests/checks/complete_directories.fish b/tests/checks/complete_directories.fish index e6fcdc1de..681a8c633 100644 --- a/tests/checks/complete_directories.fish +++ b/tests/checks/complete_directories.fish @@ -1,4 +1,5 @@ -#RUN: %fish %s +#RUN: %fish --interactive %s +# ^ interactive so we can do `complete` mkdir -p __fish_complete_directories/ cd __fish_complete_directories mkdir -p test/buildroot @@ -25,3 +26,7 @@ __fish_complete_directories test/data/ __fish_complete_directories test/data/abc 'abc dirs' #CHECK: test/data/abc/ abc dirs #CHECK: test/data/abcd/ abc dirs + +complete -c mydirs -l give-me-dir -a '(__fish_complete_directories)' +complete -C'mydirs --give-me-dir=' +#CHECK: --give-me-dir=test/{{\t}}Directory