From 0aedd47af24b5e0211daa4913716188fa6989cb9 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Tue, 2 Oct 2018 19:28:50 +0200 Subject: [PATCH] [completions/env] Argparsify This fixes subcommand completions by using argparse to get the subcommand, just like we did for `sudo`. Reported by @adregan on gitter --- share/completions/env.fish | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/share/completions/env.fish b/share/completions/env.fish index f7deca8f5..7d6fa16ad 100644 --- a/share/completions/env.fish +++ b/share/completions/env.fish @@ -1,9 +1,18 @@ +function __fish_complete_env_subcommand + argparse -s s/ignore-environment u/unset h-help v-version -- (commandline -opc) (commandline -ct) 2>/dev/null + or return + if set -q argv[1] + complete -C"$argv" + return 0 + end + return 1 +end -complete -c env -a "(set -n)=" -x -d "Redefine variable" -complete -c env -a "(__fish_complete_subcommand -- -u --unset)" -d "Command" +complete -c env -a "(__fish_complete_env_subcommand)" -d "Command" -complete -c env -s i -l ignore-environment -d "Start with an empty environment" -complete -c env -s u -l unset -d "Remove variable from the environment" -x -a "(set -n)" -complete -c env -l help -d "Display help and exit" -complete -c env -l version -d "Display version and exit" +complete -c env -n 'not __fish_complete_env_subcommand' -a "(set -n)=" -x -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"