zsh-users
 help / color / mirror / code / Atom feed
* How to complete with _arguments() depending on an option and within a loop
@ 2021-05-10 17:30 Philippe Proulx
  2021-05-11 14:12 ` Daniel Shahaf
  0 siblings, 1 reply; 7+ messages in thread
From: Philippe Proulx @ 2021-05-10 17:30 UTC (permalink / raw)
  To: zsh-users

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-05-12 16:15 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-10 17:30 How to complete with _arguments() depending on an option and within a loop Philippe Proulx
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

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).