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

Completion using state-machine



Dear all,

I need to write completion code for a complex program that can accept
different kind of arguments depending on what is already present on
the command line.  To make an short example, consider the following
specifications

{-v,--verbose} - increase verbosity of messages, can be used up to three times
{-s,--simple} - simple flag, can be used only once in the whole line
{-p,--path}=PATH - specify a directory (e.g., _files -/) for following commands
{--parameter}=PAR - set some specific parameter, can be used once for
a specified path

Note that while --simple can be used only once in the whole line,
--parameter=PAR can be used many times for differeht --path's.  For
example, the following command line is acceptable

command -vv --parameter=1 -p /tmp --parameter=2 --simple
--path=${HOME} --parameter=3

To implement this I would be tempted to use _arguments with the ->
action, which in principle would let me implement a full
state-machine.  However, although I spent the last few days in trying
to understand how to use the possibilities offered by the -> and the
$state variable to do what I need to.  I would appreciate then a
simple code example to implement the example I just provided.

Many thanks,
Marco Lombardi



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