2022-04-16 06:36:58 +00:00
|
|
|
set -l is_gnu
|
2021-12-15 16:59:12 +00:00
|
|
|
if env --version &>/dev/null
|
2022-04-16 06:36:58 +00:00
|
|
|
set is_gnu --is-gnu
|
2022-02-01 07:09:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function __fish_env_remaining_args -V is_gnu
|
2022-04-16 06:36:58 +00:00
|
|
|
set -l argv (commandline -opc) (commandline -ct)
|
2022-02-01 07:09:33 +00:00
|
|
|
if set -q is_gnu[1]
|
2022-04-16 06:36:58 +00:00
|
|
|
argparse -s i/ignore-environment u/unset= help version -- $argv 2>/dev/null
|
|
|
|
or return 0
|
2022-02-01 07:09:33 +00:00
|
|
|
else
|
2022-04-16 06:36:58 +00:00
|
|
|
argparse -s 0 i P= S= u= v -- $argv 2>/dev/null
|
|
|
|
or return 0
|
2022-02-01 07:09:33 +00:00
|
|
|
end
|
2019-05-02 14:28:12 +00:00
|
|
|
|
|
|
|
# argv[1] is `env` or an alias.
|
|
|
|
set -e argv[1]
|
|
|
|
|
|
|
|
# Remove all VAR=VAL arguments up to the first that isn't
|
|
|
|
while set -q argv[1]
|
|
|
|
if string match -q '*=*' -- $argv[1]
|
2020-01-13 19:34:22 +00:00
|
|
|
or string match -q -- '-*' $argv[1]
|
2019-05-02 14:28:12 +00:00
|
|
|
set -e argv[1]
|
|
|
|
else
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-10 06:19:06 +00:00
|
|
|
string join \n -- $argv
|
|
|
|
|
|
|
|
# Return true if there is a subcommand.
|
2022-04-16 06:36:58 +00:00
|
|
|
test -n "$argv[1]"
|
2020-10-10 06:19:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function __fish_complete_env_subcommand
|
|
|
|
if set -l argv (__fish_env_remaining_args)
|
2019-11-05 12:32:41 +00:00
|
|
|
__fish_complete_subcommand --commandline $argv
|
2018-10-02 17:28:50 +00:00
|
|
|
end
|
|
|
|
end
|
2006-12-04 11:58:38 +00:00
|
|
|
|
2019-11-05 07:44:04 +00:00
|
|
|
complete -c env -a "(__fish_complete_env_subcommand)"
|
2020-10-10 06:19:06 +00:00
|
|
|
complete -c env -n 'not __fish_env_remaining_args; and not string match -eq = -- (commandline -ct)' -a "(set -n)=" -f -d "Redefine variable"
|
2022-02-01 07:09:33 +00:00
|
|
|
|
|
|
|
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
|