From: dana <dana@dana.is>
To: Max Katsev <mkatsev@gmail.com>
Cc: zsh-workers@zsh.org
Subject: Re: possible bug in _arguments?
Date: Sun, 23 Dec 2018 23:58:12 -0600 [thread overview]
Message-ID: <38768425-6F37-4C96-8071-F97B2C97180B@dana.is> (raw)
In-Reply-To: <CAEHcyJVmOoYMYZWo8YzmnaXuzBDSb0oGBCqUHncM9SfwGojAvg@mail.gmail.com>
On 23 Dec 2018, at 16:34, Max Katsev <mkatsev@gmail.com> wrote:
>Is this a bug or am
>I missing something? Is there another way to get what I want?
I don't think optional-operand specs work like that. AFAIK, when a spec for an
optional operand n appears before one for a required operand n+1, all it tells
zsh is that it should offer both sets of possibilities at the command-line
position corresponding to n. You have to figure out yourself what to do with
an earlier operand once you're past that position.
If the command is as simple as you said, you can just do something like this:
local required
(( CURRENT > 2 )) &&
[[ $words[2] == optional ]] &&
required=':cmd2:(required)'
_arguments : ':cmd1:(optional required)' $required '*:other args:_files'
If you also need to support options, you can use the *:: form:
local ret=1 required
local -a context line state state_descr
local -A opt_args
_arguments : -a -b -c '*:: :->next' && ret=0
[[ $state == next ]] && {
words=( fake "${(@)words}" )
(( CURRENT++ ))
(( CURRENT > 2 )) &&
[[ $words[2] == optional ]] &&
required=':cmd2:(required)'
_arguments : \
':cmd1:(optional required)' $required '*:other args:_files' \
&& ret=0
}
return ret
Something like that, at least; there are lots of ways you could handle it
dana
prev parent reply other threads:[~2018-12-24 5:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-23 22:34 Max Katsev
2018-12-24 5:58 ` dana [this message]
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=38768425-6F37-4C96-8071-F97B2C97180B@dana.is \
--to=dana@dana.is \
--cc=mkatsev@gmail.com \
--cc=zsh-workers@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).