From: Philippe Proulx <eeppeliteloop@gmail.com>
To: zsh-users@zsh.org
Subject: How to complete with _arguments() depending on an option and within a loop
Date: Mon, 10 May 2021 13:30:38 -0400 [thread overview]
Message-ID: <CAB4xu_0RM08GhVq3crr3eA0qpYumEEP5vZL5PgoFuaaY4q9JBA@mail.gmail.com> (raw)
I'm in the process of writing a Zsh completion script.
Consider this command line:
$ prog --state=foo --meow --state=bar cola --mix --lol=34 \
--state=foo --meow --zoom
In a Zsh completion script, how would you complete the options above,
knowing that:
* You can specify one or more _groups_.
* A group starts with the `--state` option which accepts an argument.
* The accepted options depend on the argument of the preceding `--state`
option.
For example:
* With `--state=foo`, you can pass `--meow` (only once) and
`--zoom` (only once).
* With `--state=bar`:
* You can pass `--mix` (only once), `--lol` (only once).
* You must pass a non-option argument (`cola` in this example).
* Wherever you are, Zsh must always offer you the `--state` option with
the `foo` and `bar` arguments (to restart).
I managed to implement such a completion script "manually", with the
`words` and `CURRENT` variables, compset(), and _describe() to add
completions. It works, but I feel like I'm rewriting parts of
_arguments().
Is there a known way to achieve this mostly with _arguments()?
Thank you,
Phil
next reply other threads:[~2021-05-10 17:36 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-10 17:30 Philippe Proulx [this message]
2021-05-11 14:12 ` Daniel Shahaf
2021-05-12 13:44 ` Philippe Proulx
2021-05-12 15:11 ` Bart Schaefer
2021-05-12 15:14 ` Philippe Proulx
2021-05-12 15:50 ` Bart Schaefer
2021-05-12 16:14 ` Ray Andrews
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=CAB4xu_0RM08GhVq3crr3eA0qpYumEEP5vZL5PgoFuaaY4q9JBA@mail.gmail.com \
--to=eeppeliteloop@gmail.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).