From a635d78976f80e625338442d552fbfc3df90471a Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sat, 10 Oct 2020 08:19:06 +0200 Subject: [PATCH] competions/env: only invoke subcommand completions once This prevents a seemingly infinite loop in fish -c 'alias ssh "env ssh"; complete -C "ssh "' It still prints "maximum recursion depth exceeded", but a follow-up commit will work around that. Fixes #7389 --- share/completions/env.fish | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/share/completions/env.fish b/share/completions/env.fish index 3e231cc66..ef7284bcc 100644 --- a/share/completions/env.fish +++ b/share/completions/env.fish @@ -1,4 +1,4 @@ -function __fish_complete_env_subcommand +function __fish_env_remaining_args argparse -s s/ignore-environment u/unset= h-help v-version -- (commandline -opc) (commandline -ct) 2>/dev/null or return 1 @@ -15,19 +15,23 @@ function __fish_complete_env_subcommand end end - # Then complete the rest as if it was given as a command. - if test -n "$argv" + string join \n -- $argv + + # Return true if there is a subcommand. + set -q argv[1] +end + +function __fish_complete_env_subcommand + if set -l argv (__fish_env_remaining_args) __fish_complete_subcommand --commandline $argv - return 0 end - return 1 end complete -c env -a "(__fish_complete_env_subcommand)" # complete VAR= only if the cursor is left of the =, otherwise complete the file right of the = -complete -c env -n 'not __fish_complete_env_subcommand; and not string match -eq = -- (commandline -ct)' -a "(set -n)=" -f -d "Redefine variable" -complete -c env -n 'not __fish_complete_env_subcommand' -s i -l ignore-environment -d "Start with an empty environment" -complete -c env -n 'not __fish_complete_env_subcommand' -s u -l unset -d "Remove variable from the environment" -x -a "(set -n)" -complete -c env -n 'not __fish_complete_env_subcommand' -l help -d "Display help and exit" -complete -c env -n 'not __fish_complete_env_subcommand' -l version -d "Display version and exit" +complete -c env -n 'not __fish_env_remaining_args; and not string match -eq = -- (commandline -ct)' -a "(set -n)=" -f -d "Redefine variable" +complete -c env -n 'not __fish_env_remaining_args' -s i -l ignore-environment -d "Start with an empty environment" +complete -c env -n 'not __fish_env_remaining_args' -s u -l unset -d "Remove variable from the environment" -x -a "(set -n)" +complete -c env -n 'not __fish_env_remaining_args' -l help -d "Display help and exit" +complete -c env -n 'not __fish_env_remaining_args' -l version -d "Display version and exit"