I am trying to improve the completion for the gradle command, and have run into something I cannot explain. To simplify things as much as possible, I have constructed this example file, calling it _myfoo: #compdef myfoo local curcontext="$curcontext" ret=1 state _arguments -C \ '--option1' \ '--option2' \ '*:a subcommand:->subcommand' \ && ret=0 if [[ -n $state ]]; then print state: $state > /dev/pty2 fi return ret On the command line, I write: "myfoo --", and the completion kicks in and gives me the options "--option1" and "--option2", which is what I expected. However, on /dev/pty2 I see "state: subcommand", which I did NOT expect. I would have thought that since only "--option1" or "--option2" could possibly match after "--", state would not have been set*, *but it is. The trouble with this is that in the gradle completion, the possible subcommands are generated inside the if statement in this case, and thatis time consuming. I would thus like to avoid going into it when the "--" on the command line indicates that an option should be completed. I would have thought that the call to _arguments did not set state since found some matching options, but obviously I am using it incorrectly. What should I do instead?