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

Re: Putting options after tasks



On Mar 14,  9:53am, Jesper Nygårds wrote:
}
} What do I have to do to make it possible to complete options after tasks?

_arguments is designed to assume that programs accept all options first
and all other arguments after them.  If you have a program that doesn't
follow that convention, you may be able to use _regex_arguments (good
luck there, I'm not sure there's anyone still reading this list who has
any experience with it) or will need to write your own loop over the
$words array.

Given that the tasks and options can be freely mixed in this way, I
presume that none of the options take a following argument (that is,
"--foobar zoom" never means that "zoom" must appear immediately after
"--foobar").

If that's true, then one possibility is to make a first loop over the
$words array and insert a "+" sign in front of all the task names (but
stop before, or skip over, $words[CURRENT]), so that _arguments can
interpret as options the words you are NOT completing.  In that same
loop over the words, build up a a list of dummy option specs to pass
to _arguments so it knows to skip them.  Then add those dummy specs to
the real specs when making the _arguments call.

At the end, loop over $words again and remove the "+" signs you added
before returning $ret.  This may not be necessary but will avoid conflict
with other completers later.



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