Zsh Mailing List Archive
Messages sorted by:
Re: completion: _normal after argument
On Mon, 28 Jul 2014 12:16:10 +0000 (UTC)
Martin Vaeth <martin@xxxxxxxx> wrote:
> for some scripts I am currently writing some completion functions.
> The syntax of the call should be
> foo [lots of complicated options] CMD [shell-command with options]
> Naturally, since the options can be treated with _arguments in
> a standard way, I want to use something like
> _arguments -C -s -S -A '-*' : \
> --optA=.... \
> --optB... \
> -q... \
> '1:command:->cmds' \
> It is clear to me what to do in case $state == cmds
> But what to do in case $state == normal?
> Essentially, I want to call of course _normal
> (after cutting the "options+CMD" part from the words array and
> decreasing the CURRENT parameter correspondingly).
> But how to find where the "options+CMD" part has finished?
You can use _arguments -n.
With the option -n, _arguments sets the parameter NORMARG to the
position of the first normal argument in the $words array, i.e.
the position after the end of the options. If that argument has
not been reached, NORMARG is set to -1. The caller should
declare `integer NORMARG' if the -n option is passed; otherwise
the parameter is not used.
Supposedly you don't even need to do that, however:
This describes how arguments (usually non-option argu‐
ments, those not beginning with - or +) are to be com‐
pleted when neither of the first two forms was provided.
Any number of arguments can be completed in this fashion.
With two colons before the message, the words special
array and the CURRENT special parameter are modified to
refer only to the normal arguments when the action is
executed or evaluated. With three colons before the mes‐
sage they are modified to refer only to the normal argu‐
ments covered by this description.
I have a feeling I've had trouble with that in the past though (and,
obviously, no one in their senses would try to understand _arguments).
Messages sorted by: