__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"`)
This commit is contained in:
Fabian Boehm
2024-12-30 20:59:38 +01:00
parent e715c3e3ff
commit d5efef1cc5

View File

@@ -10,34 +10,31 @@ 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]
set -e cmd[1]
if contains -- $token $options_with_param
set skip_next (math $skip_next + 1)
set -l cmd (commandline -cxp | string escape) (commandline -ct)
while set -q cmd[1]
set -l token $cmd[1]
set -e cmd[1]
if contains -- $token $options_with_param
set skip_next (math $skip_next + 1)
continue
end
switch $token
case '-*' '*=*'
continue
end
switch $token
case '-*' '*=*'
case '*'
if test $skip_next -gt 0
set skip_next (math $skip_next - 1)
continue
case '*'
if test $skip_next -gt 0
set skip_next (math $skip_next - 1)
continue
end
# found the start of our command
set subcommand $token $cmd
break
end
end
# found the start of our command
set subcommand $token $cmd
break
end
end