I want to write zsh completions for a program with the following calling convention:
program [generaloptions] operation [operationoptions]
where operation
is one of --install
, --upgrade
...
What I have so far, are the general options and the operation options. My code looks something like this:
local generaloptions; generaloptions=(...)
local installoptions; installoptions=(...)
local upgradeoptions; upgradeoptions=(...)
case "$state" in
(install)
_arguments -s \
"$installoptions[@]" \
&& ret=0
(upgrade)
_arguments -s \
"$upgradeoption[@]" \
&& ret=0
*)
_arguments -s \
"$generaloptions[@]" \
'--install[...]: :->install' \
'--upgrade[...]: :->upgrade' \
&& ret=0
The problem is, after I type the operation and the first operation option, the state gets reset to the *)
case.
Example
$ program --install --installoption --<tab>
list of general options
How can I set the next state to be the same as the old? Which command has similar calling conventions, so I can look at the code of the completion for this command?