Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Putting options after tasks
- X-seq: zsh-users 16878
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: Putting options after tasks
- Date: Wed, 14 Mar 2012 10:19:17 -0700
- In-reply-to: <CABZhJg9sya0JmRYG+2OYw6nb=eX ZBj37fFXn Jit1fTK8zrDw@mail.gmail.com>Comments: In reply to Jesper Nygårds <jesper.nygards@gmail.com> "Putting options after tasks" (Mar 14, 9:53am)
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CABZhJg9sya0JmRYG+2OYw6nb=eX_ZBj37fFXn_Jit1fTK8zrDw@mail.gmail.com>
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