Zsh completion basics: Difference between revisions
From wikinotes
Line 35: | Line 35: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
_arguments \ | _arguments \ | ||
'1:name:(alex will maize)' | '1:name:(alex will maize)' \ # completion choices for positional arg | ||
{-c,--component}":component:(mail calendar contacts tasks memos)" \ # completion choices for keyword arg | |||
</syntaxhighlight> | </syntaxhighlight> | ||
</blockquote><!-- Actions --> | </blockquote><!-- Actions --> |
Latest revision as of 20:21, 5 November 2023
Simple Example
# compdef backup_user # <-- program(s) to complete _arguments \ '1:firstname:_normal' \ # <-- positional param 1 '2:file:_normal' # <-- positional param 2 '3::foo:_normal' # <-- optional positional param 3 (2x ::) {-h,--help}'[show help]' \ # <-- flag param (no value) '-o[output file]::outfile:_files' \ # <-- flag param (with 'file' value)
Actions
Actions are used in params that require a followup value param.
They determine the types of completions that will be suggested.There is a large variety of builtin functions like these:
# usage _arguments \ '1:name:_normal' # some useful actions: _normal # complete a word _parameters # one or more normal args _files # complete filepaths _user # complete from OS users _groups # complete from OS groupsYou can also provide an array of choices
_arguments \ '1:name:(alex will maize)' \ # completion choices for positional arg {-c,--component}":component:(mail calendar contacts tasks memos)" \ # completion choices for keyword arg