Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Possible to use _arguments with _regex_arguments?
- X-seq: zsh-users 24250
- From: "Ronan Pigott" <rpigott314@xxxxxxxxx>
- To: <zsh-users@xxxxxxx>
- Subject: Possible to use _arguments with _regex_arguments?
- Date: Tue, 17 Sep 2019 19:31:04 -0700
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=content-transfer-encoding:date:subject:from:to:message-id; bh=WySwvesatUg9ionLiRin3aInQl04zwx5ZPYhNIOmbkc=; b=nFaZg52y8itD5IyqIizYEu6W0hEGmaN3s7mZetB1X9mwk4QETuxU0ZU7XXU5Ta5fdv FxnaloO46VEVRiYOR96+mVC9TeORF+ebr/2LsqPNFb6gteSP1XUykIJ6vwW/S9Wl1Lg6 nDgolrxJxjzufE0g2QDqZlPZuhE/46ZXxy/oikZ2UmguaWNcYJ9Sn5cpKjLlu+DxHHj5 0ceYXK/7kqcbbZGhrB9KSGjkG6Pkx73djs+WiLxETvbIvuXFZgxFSFzjM8t1j+KU3yjN ZQlwp73Y31jC5gf+KLInV3KResMxYPNMJmfMQJ6WnC8h5X7VSaWkbRg81JH9uDGzxXyW hv+Q==
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
Hello,
I've written a number of zsh completions recently and I find that
generally there are two patterns that work well, with _arguments using
->state to dispatch completions and _regex_arguments to build a regex
state machine.
Often I find that I'd like to use both _arguments and _regex_arguments
together, using _arguments to parse the opt_args and _regex_arguments to
handle the rest. I think it would have some advantages over building the
whole completion in _regex_arguments. _arguments already closely resembles
the behavior of getopt, consuming arguments it recognizes and leaving
the remainder in $line for dispatched functions to consider. It also
easily supports behavior where it ignores flags following a '--'
argument, which is not trivial to replicate with _regex_arguments.
Ideally, I think it would be possible to use _arguments to
define the flagged arguments I want to check and keep their values in
opt_args, but use a _regex_arguments function as an action for
_arguments acting on $line, like so:
```
_regex_arguments _myfunc ...
_arguments -S -s \
{-o+,--option}'[An option]:tag:(some values)'
'*:positional arguments:_myfunc'
```
However, in the above case, if _myfunc was not carefully crafted to ignore
'--option' it will fail to match and provide no completions because _myfunc
operates exclusively on $words. Is it possible to use _regex_arguments
functions on anything else, or in any other context?
One thing I thought to try was set '{words=("$line[@]"); _myfunc}' for
the action, but it did not seem to work.
If it cannot be done, is there another way that I can transform the line
to be completed before running (or re-running) the completion to make
this idea possible?
Messages sorted by:
Reverse Date,
Date,
Thread,
Author