env completions: Update for FreeBSD env

This isn't perfect, NetBSD for example takes -0 but not -v, -P,
or -S.
This commit is contained in:
Aaron Gyes 2022-01-31 23:09:33 -08:00
parent 12a4091774
commit c75603c475

View file

@ -1,6 +1,15 @@
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
if env --version &> /dev/null
set -l is_gnu --is-gnu
end
function __fish_env_remaining_args -V is_gnu
if set -q is_gnu[1]
argparse -s i/ignore-environment u/unset= help version -- (commandline -opc) (commandline -ct) 2>/dev/null
or return 1
else
argparse -s 0 i P= S= u= v -- (commandline -opc) (commandline -ct) 2>/dev/null
or return 1
end
# argv[1] is `env` or an alias.
set -e argv[1]
@ -28,10 +37,20 @@ function __fish_complete_env_subcommand
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_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"
if set -q is_gnu
# complete VAR= only if the cursor is left of the =, otherwise complete the file right of the =
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 "Unset environment variable" -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"
else
# complete VAR= only if the cursor is left of the =, otherwise complete the file right of the =
complete -c env -n 'not __fish_env_remaining_args' -s 0 -d "End output lines with NUL"
complete -c env -n 'not __fish_env_remaining_args' -s i -d "Start with empty environment"
complete -c env -n 'not __fish_env_remaining_args' -s P -d "Provide an alternate PATH"
complete -c env -n 'not __fish_env_remaining_args' -s S -d "Split argument into args on ' '"
complete -c env -n 'not __fish_env_remaining_args' -s u -d "Unset environment variable" -x -a "(set -n)"
complete -c env -n 'not __fish_env_remaining_args' -s v -d "Verbose output on processing"
end