From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-users@zsh.org
Subject: Re: completion: _normal after argument
Date: Mon, 28 Jul 2014 21:12:47 +0100 [thread overview]
Message-ID: <20140728211247.09469e0d@pws-pc.ntlworld.com> (raw)
In-Reply-To: <slrnltcfo8.nnr.martin@epidot.math.uni-rostock.de>
On Mon, 28 Jul 2014 12:16:10 +0000 (UTC)
Martin Vaeth <martin@mvath.de> 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' \
> '*::command:->normal'
>
> 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:
*:::message:action
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).
pws
next prev parent reply other threads:[~2014-07-28 20:19 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-28 12:16 Martin Vaeth
2014-07-28 20:12 ` Peter Stephenson [this message]
2014-07-29 2:54 ` Bart Schaefer
2014-07-29 7:37 ` Oliver Kiddle
2014-07-29 8:50 ` Martin Vaeth
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140728211247.09469e0d@pws-pc.ntlworld.com \
--to=p.w.stephenson@ntlworld.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).