Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

How to complete with _arguments() depending on an option and within a loop



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




Messages sorted by: Reverse Date, Date, Thread, Author