__fish_complete_subcommand: Just complete -C for a given commandline

Fixes #10980.

This would, if a commandline was given, still revert to checking
the *real* commandline if it was empty.

Unfortunately, in those cases, it could have found a command and tried
to complete it.

If a commandline is given, that is what needs to be completed.

(note this means this is basically useless in completions that use it
like `sudo` and could just be replaced with `complete -C"$commandline"`)

(cherry picked from commit d5efef1cc5)
This commit is contained in:
Fabian Boehm
2024-12-30 20:59:38 +01:00
parent ff8a879e80
commit 5845a3f7ad

View File

@@ -10,14 +10,12 @@ function __fish_complete_subcommand -d "Complete subcommand" --no-scope-shadowin
case '--fcs-skip=*'
set skip_next (string split = -- $arg)[2]
case --commandline # --commandline means to use our arguments instead of the commandline.
set subcommand $argv
set -e argv
break
complete -C "$argv"
return
end
end
set -l options_with_param $argv
if not string length -q -- $subcommand
set -l cmd (commandline -cxp | string escape) (commandline -ct)
while set -q cmd[1]
set -l token $cmd[1]
@@ -39,7 +37,6 @@ function __fish_complete_subcommand -d "Complete subcommand" --no-scope-shadowin
break
end
end
end
printf "%s\n" (complete -C "$subcommand")
end