Zsh completion basics: Difference between revisions
From wikinotes
No edit summary |
|||
(5 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
= | = Simple Example = | ||
<blockquote> | <blockquote> | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
Line 7: | Line 7: | ||
'1:firstname:_normal' \ # <-- positional param 1 | '1:firstname:_normal' \ # <-- positional param 1 | ||
'2:file:_normal' # <-- positional param 2 | '2:file:_normal' # <-- positional param 2 | ||
'3::foo:_normal' # <-- optional positional param 3 (2x ::) | |||
{-h,--help}'[show help]' \ # <-- flag param (no value) | {-h,--help}'[show help]' \ # <-- flag param (no value) | ||
'-o[output file]::outfile:_files' \ # <-- flag param (with 'file' value) | '-o[output file]::outfile:_files' \ # <-- flag param (with 'file' value) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</blockquote><!-- | </blockquote><!-- Simple Example --> | ||
= Actions = | = Actions = | ||
Line 17: | Line 18: | ||
They determine the types of completions that will be suggested. | They determine the types of completions that will be suggested. | ||
There is a large variety of builtin functions like these: | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
# usage | |||
_arguments \ | |||
'1:name:_normal' | |||
# some useful actions: | |||
_normal # complete a word | _normal # complete a word | ||
_files | _parameters # one or more normal args | ||
_files # complete filepaths | |||
_user # complete from OS users | _user # complete from OS users | ||
_groups # complete from OS groups | _groups # complete from OS groups | ||
</syntaxhighlight> | |||
You can also provide an array of choices | |||
<syntaxhighlight lang="bash"> | |||
_arguments \ | |||
'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