update
This commit is contained in:
parent
79878668e5
commit
4775d6edf3
|
@ -78,7 +78,7 @@ Examples of how to use these functions are given in the next section.
|
||||||
| _describe | Used for creating simple completions consisting of single words with descriptions (but no actions). Easier to use than _arguments |
|
| _describe | Used for creating simple completions consisting of single words with descriptions (but no actions). Easier to use than _arguments |
|
||||||
| _gnu_generic | Can be used to complete options for commands that understand the `--help' option. |
|
| _gnu_generic | Can be used to complete options for commands that understand the `--help' option. |
|
||||||
| _regex_arguments | Creates a function for matching commandline arguments with regular expressions, and then performing actions/completions. |
|
| _regex_arguments | Creates a function for matching commandline arguments with regular expressions, and then performing actions/completions. |
|
||||||
*** functions for performing complex completions
|
*** functions for performing complex individual completions
|
||||||
| _values | Used for completing arbitrary keywords (values) and their arguments, or comma separated lists of such combinations. |
|
| _values | Used for completing arbitrary keywords (values) and their arguments, or comma separated lists of such combinations. |
|
||||||
| _combination | Used to complete combinations of values, for example pairs of hostnames and usernames. |
|
| _combination | Used to complete combinations of values, for example pairs of hostnames and usernames. |
|
||||||
| _multi_parts | Used for completing multiple parts of words separately where each part is separated by some char, e.g. for completing partial filepaths: /u/i/sy -> /usr/include/sys |
|
| _multi_parts | Used for completing multiple parts of words separately where each part is separated by some char, e.g. for completing partial filepaths: /u/i/sy -> /usr/include/sys |
|
||||||
|
@ -106,7 +106,7 @@ at the end of an option/argument specification. This action indicates how to com
|
||||||
The actions can take one of the following forms:
|
The actions can take one of the following forms:
|
||||||
| ( ) | Argument is required but no matches are generated for it. |
|
| ( ) | Argument is required but no matches are generated for it. |
|
||||||
| (ITEM1 ITEM2) | List of possible matches |
|
| (ITEM1 ITEM2) | List of possible matches |
|
||||||
| ((ITEM1\:DESC1 ITEM2\:DESC2)) | List of possible matches, with descriptions. |
|
| ((ITEM1\:'DESC1' ITEM2\:'DESC2')) | List of possible matches, with descriptions. Make sure to use different quotes than those around the whole specification. |
|
||||||
| ->STRING | Set $state to STRING and continue ($state can be checked in a case statement after the utility function call) |
|
| ->STRING | Set $state to STRING and continue ($state can be checked in a case statement after the utility function call) |
|
||||||
| FUNCTION | Name of a function to call for generating matches or performing some other action, e.g. _files or _message |
|
| FUNCTION | Name of a function to call for generating matches or performing some other action, e.g. _files or _message |
|
||||||
| {EVAL-STRING} | Evaluate string as shell code to generate matches. This can be used to call a utility function with arguments, e.g. _values or _describe |
|
| {EVAL-STRING} | Evaluate string as shell code to generate matches. This can be used to call a utility function with arguments, e.g. _values or _describe |
|
||||||
|
@ -138,8 +138,8 @@ In this case you will have to put it in braces with its arguments, e.g. 'TAG:DES
|
||||||
Like _describe, this function performs simple completions where the order and position of options/arguments is not important.
|
Like _describe, this function performs simple completions where the order and position of options/arguments is not important.
|
||||||
However, unlike _describe, you can call execute shell code or call functions to obtain the completion candidates.
|
However, unlike _describe, you can call execute shell code or call functions to obtain the completion candidates.
|
||||||
|
|
||||||
As arguments it takes a list of specifications each in the form `TAG:DESCR:ACTION' where TAG is a tag name,
|
As arguments it takes a list of specifications each in the form `TAG:DESCRIPTION:ACTION' where TAG is a tag name,
|
||||||
DESCR is a description, and ACTION is one of the action types listed previously.
|
DESCRIPTION is a description, and ACTION is one of the action types listed previously (apart from the ->STRING and =ACTION forms).
|
||||||
For example:
|
For example:
|
||||||
#+BEGIN_SRC sh
|
#+BEGIN_SRC sh
|
||||||
_alternative 'args:custom args:(a b c)' 'files:filenames:_files'
|
_alternative 'args:custom args:(a b c)' 'files:filenames:_files'
|
||||||
|
@ -174,10 +174,20 @@ _alternative "dirs:user directories:($userdirs)"\
|
||||||
'opts:comma separated opts:{_values -s , a b c}'
|
'opts:comma separated opts:{_values -s , a b c}'
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
|
||||||
The _alternative function can itself be used in an ACTION as part of a specification for _arguments or _regex_arguments.
|
As with _describe, the _alternative function can itself be used in an ACTION as part of a specification for _arguments
|
||||||
In this case you will have to put it in braces with its arguments, e.g. 'TAG:DESCRIPTION:{_alternative 'values' options}'
|
or _regex_arguments.
|
||||||
** Writing completion functions using _arguments
|
** Writing completion functions using _arguments
|
||||||
With the _arguments function you can create much more sophisticated completion functions.
|
With the _arguments function you can create much more sophisticated completion functions.
|
||||||
|
Like the _alternative function, _arguments takes a list of specification strings as arguments.
|
||||||
|
These specification strings can be for specifying options and any corresponding option arguments (e.g. -f filename),
|
||||||
|
or command arguments.
|
||||||
|
Basic option specifications take the form '-OPT[DESCRIPTION]'. Arguments for the option can be specified after the option
|
||||||
|
description like this '-OPT[DESCRIPTION]:MESSAGE1:ACTION1:MESSAGE2:ACTION2' where MESSAGE1 & MESSAGE2 are the messages
|
||||||
|
printed for the first and second args, and ACTION1 & ACTION2 determine how the completion candidates for those args
|
||||||
|
are determined (see the ACTIONS section above).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
As arguments it takes special strings specifying the options & arguments to the function being completed,
|
As arguments it takes special strings specifying the options & arguments to the function being completed,
|
||||||
e.g. like this:
|
e.g. like this:
|
||||||
#+BEGIN_SRC sh
|
#+BEGIN_SRC sh
|
||||||
|
@ -207,9 +217,10 @@ If the default keybindings don't work you can try pressing Alt+x and then enter
|
||||||
| _complete_help | Ctrl+x h | displays information about context names, tags, and completion functions used when completing at the current cursor position |
|
| _complete_help | Ctrl+x h | displays information about context names, tags, and completion functions used when completing at the current cursor position |
|
||||||
| _complete_help | Alt+2 Ctrl+x h | as above but displays even more information |
|
| _complete_help | Alt+2 Ctrl+x h | as above but displays even more information |
|
||||||
| _complete_debug | Ctrl+x ? | performs ordinary completion, but captures in a temporary file a trace of the shell commands executed by the completion system |
|
| _complete_debug | Ctrl+x ? | performs ordinary completion, but captures in a temporary file a trace of the shell commands executed by the completion system |
|
||||||
* Gotchas
|
* Gotchas (things to watch out for)
|
||||||
Take care to use the correct type of quotes around specifications to _arguments or _regex_arguments:
|
Take care to use the correct type of quoting for specifications to _arguments or _regex_arguments:
|
||||||
use double quotes if there is a parameter that needs to be expanded in the specification, single quotes otherwise.
|
use double quotes if there is a parameter that needs to be expanded in the specification, single quotes otherwise,
|
||||||
|
and make sure to use different quotes around item descriptions.
|
||||||
* Putting it all together
|
* Putting it all together
|
||||||
* Other resources
|
* Other resources
|
||||||
[[http://wikimatze.de/writing-zsh-completion-for-padrino.html][Here]] is a nicely formatted short tutorial showing basic usage of the _arguments function,
|
[[http://wikimatze.de/writing-zsh-completion-for-padrino.html][Here]] is a nicely formatted short tutorial showing basic usage of the _arguments function,
|
||||||
|
|
Loading…
Reference in New Issue