zsh argument completion
Some help how to define arguments for a zsh completion
#compdef the_command
#autoload
# basic subcommands, like docker run
local -a _1st_arguments
_1st_arguments=(
'run'
'exec'
'rm'
)
# function to parse the subcommands
_the_command_subcommand() {
case "$words[1]" in
'run')
_alternative "the_command_run:the_command run:"
return
;;
'exec')
_arguments "(-t)-t[some description]"
return
;;
esac
}
_arguments -C '*:: :->subcmds'
if (( CURRENT == 1 ));then
_describe -t commands "the_command command" _1st_arguments
return
fi
_the_command_subcommand
A simple option with an alternative short name and with description. It also expects a value after the option.
_arguments \
'(-o --option-name)'{-o,--option-name}'[Describe what the option is good for]:option name:' \
&& return 0
Example:
the_command -o foobar
# or
the_command --option-name freetext
A simple option with an alternative short name and with description, and provide a fix list as the value of the options
_arguments \
'(-o --option-name)'{-o,--option-name}'[Describe what the option is good for]:option name:(foo bar baz)' \
&& return 0
Example:
the_command -o foo
# or
the_command --option-name bar
A simple option with an alternative short name and with description, and a shell script which generates the possible values
_arguments \
'(-o --option-name)'{-o,--option-name}'[Describe what the option is good for]:option name:($(the-shell-script))' \
&& return 0
A simple option with an alternative short name and with description, and provide a function which can generate the available options
_command_option_values() {
compadd $(shell script where every word is an completion string)
}
_arguments \
'(-o --option-name)'{-o,--option-name}'[Describe what the option is good for]:option name:_command_option_values' \
&& return 0
Hozzászóláshoz a Disqus szolgáltatását használom, korábbi vélemények elovlasásához és új hozzászólás írásához engedélyezd a Disqus-tól származó JavaScripteteket.