From 330c97d24dde804713971243d80e33f146227c3e Mon Sep 17 00:00:00 2001 From: Joe Bloggs Date: Wed, 26 Mar 2014 18:23:21 +0000 Subject: [PATCH] update --- zsh-completions-howto.org | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/zsh-completions-howto.org b/zsh-completions-howto.org index 42d7bf8..e5823ba 100644 --- a/zsh-completions-howto.org +++ b/zsh-completions-howto.org @@ -178,7 +178,7 @@ this will complete the items in $userdirs, aswell as a comma separated list cont As with _describe, the _alternative function can itself be used in an ACTION as part of a specification for _arguments or _regex_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 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. @@ -226,6 +226,27 @@ I have just given you the basics of _arguments specifications here, you can also repeated options & arguments, options beginning with + insead of -, etc. For more details see the [[http://zsh.sourceforge.net/Doc/Release/Completion-System.html#Completion-System][official documentation]]. Also have a look at the tutorials mentioned at the end of this document, and the completion functions in the [[https://github.com/vapniks/zsh-completions/tree/master/src][src directory]]. ** Writing completion functions using _regex_arguments and _regex_words +If you have a complex command line specification with several different possible argument sequences then +the _regex_arguments function may be what you need. + +_regex_arguments creates a completion function whose name is given by the first argument. +Hence you need to first call _regex_arguments to create the completion function, and then call that function, +e.g. like this: +#+BEGIN_SRC sh +_regex_arguments _cmd OTHER_ARGS.. +_cmd "$@" +#+END_SRC + +The OTHER_ARGS should be sequences of specifications for matching & completing sequences of words on the command line. +These sequences can be separated by '|' to represent alternative command line specifications, and you can use +bracketing to arbitrary depth to specify alternate subsequences. +For example: +#+BEGIN_SRC sh +_regex_arguments SEQ1 '|' SEQ2 \( SEQ2a '|' SEQ2b \) +#+END_SRC +this specifies a command line matching either SEQ1, or SEQ2 followed by SEQ2a or SEQ2b. + + *** Patterns * Testing & debugging To reload a completion function: