2018-10-03 01:28:50 +08:00
|
|
|
function __fish_complete_env_subcommand
|
2019-11-05 15:44:04 +08:00
|
|
|
argparse -s s/ignore-environment u/unset= h-help v-version -- (commandline -opc) (commandline -ct) 2>/dev/null
|
|
|
|
or return 1
|
2019-05-02 22:28:12 +08: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-14 03:34:22 +08:00
|
|
|
or string match -q -- '-*' $argv[1]
|
2019-05-02 22:28:12 +08:00
|
|
|
set -e argv[1]
|
|
|
|
else
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Then complete the rest as if it was given as a command.
|
2019-11-05 15:44:04 +08:00
|
|
|
if test -n "$argv"
|
2019-11-05 20:32:41 +08:00
|
|
|
__fish_complete_subcommand --commandline $argv
|
2018-10-03 01:28:50 +08:00
|
|
|
return 0
|
|
|
|
end
|
|
|
|
return 1
|
|
|
|
end
|
2006-12-04 19:58:38 +08:00
|
|
|
|
2019-11-05 15:44:04 +08:00
|
|
|
complete -c env -a "(__fish_complete_env_subcommand)"
|
2006-12-04 19:58:38 +08:00
|
|
|
|
2019-11-05 15:44:04 +08:00
|
|
|
# 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"
|
2018-10-03 01:28:50 +08:00
|
|
|
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"
|