Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: possible bug in _arguments?
- X-seq: zsh-workers 43933
- From: dana <dana@xxxxxxx>
- To: Max Katsev <mkatsev@xxxxxxxxx>
- Subject: Re: possible bug in _arguments?
- Date: Sun, 23 Dec 2018 23:58:12 -0600
- Cc: zsh-workers@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dana-is.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=uT6dEgL3CibPRdsFj7sKPZ5/qHGyVpJI3v6arEIz7GI=; b=S0cFmL1mwEQ8tv32mYfpk1YdITwzQjFPfIEvE0SS0bJfYaFng7sD+vIsvnnOU/e7y9 RNqEn3sOYHr+5tR/StcgmKvTTWLty0MVRwcCfm2tqhuFrL73Gx74fiRUx8vGfl0IAZHQ uPd9AATiUjBwuGNy8McRCiKqiYpDCLcvBWLgnKB/39I8SXyfdc3ib8fGoFvt/Yvazx3Z 73IAioyk58TzmZKpPfGAMV2QlkHJdOFrmpUwidzyLDZzw6roD/uOzgneJgo1/Ivx+hL9 3fmj1NgLI9E67DjXS65M4sx6VjgOOZHC27aN0ar5oWCBanzEMHx/2tID+vLO22jhVT0J gWSQ==
- In-reply-to: <CAEHcyJVmOoYMYZWo8YzmnaXuzBDSb0oGBCqUHncM9SfwGojAvg@mail.gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CAEHcyJVmOoYMYZWo8YzmnaXuzBDSb0oGBCqUHncM9SfwGojAvg@mail.gmail.com>
On 23 Dec 2018, at 16:34, Max Katsev <mkatsev@xxxxxxxxx> 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author