From 5845a3f7ad42ff5a9342529e9b3b26e61b45fa3f Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Mon, 30 Dec 2024 20:59:38 +0100 Subject: [PATCH] __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 d5efef1cc52091066f93843dad52b472738c62f7) --- .../functions/__fish_complete_subcommand.fish | 41 +++++++++---------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/share/functions/__fish_complete_subcommand.fish b/share/functions/__fish_complete_subcommand.fish index a5a05b150..f531d1f53 100644 --- a/share/functions/__fish_complete_subcommand.fish +++ b/share/functions/__fish_complete_subcommand.fish @@ -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