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

Re: Using the same completion function for various commands



On 6 December 2010 15:12, Martin Richter
<mrichter@xxxxxxxxxxxxxxxxxxxxxxxx> wrote:
> Hello,
>
> I'm searching the documentation for quite a while now but can't figure out how
> to do the following:
>
> I wrote a completion function which resides somewhere in $fpath, let's call it
> _foo. But I don't want to have it applied on the command foo only. I want to use
> it on all commands matching a certain pattern, e.g. foo_1, foo_2, ... (or foo_*
> for short). Is it possible to define a context for this (like
> :completion::complete:foo_*::) and use zstyle to bind this completer to it?
> Unfortunately I couldn't figure out how.
> Âzstyle "*" completer _<TAB>
> only tells me about some built-ins.
>
> Thank you very much and please forgive me in case I oversaw something obvious in
> the documentation.

       #compdef names... [ -[pP] patterns... [ -N names... ] ]
              The file will be made autoloadable and the function
defined in it will
              be called when completing names, each of which is either
the name of a
[...]
              If the #compdef line contains one of the options -p or
-P,  the  words
              following  are taken to be patterns.  The function will
be called when
              completion is attempted for a command or context that
matches  one  of
              the  patterns.   The options -p and -P are used to
specify patterns to

You can also do this in your .zshrc instead of in the completer if you
wish, just write
compdef _foo -p 'foo_*'

At least that's what the documentation says, it doesn't seem to work that well.

-- 
Mikael Magnusson



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