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

Re: Use of (e:...:) glob qualifier with _files -g?



On Mon, Nov 4, 2019 at 2:42 PM Chris Nebel <c.nebel@xxxxxxx> wrote:
>
> My problem then becomes how to let people configure the completion so they can use any extensions I didn’t cover.  I’m guessing that the answer has something to do with zstyle and the “file-patterns” style, but I’m having trouble turning the examples in zshcompsys(1) into something that works.  To make this a bit more concrete, say my completion code looks something like this:
>
>         files -g '*.(cpio|tar|xar)'
>
> …and someone wants to also match “*.cpgz” files, what would they do?

Typically you would assign the pattern to a variable, and then use a
style to allow the user to substitute his own value for that variable.
You can name the style anything you like, but a usual approach would
be to choose a name that is already in use for similar purposes.  If
you call the existing _files completer it will handle the zstyle
lookup.

You need to determine a context name for your completion and assign
that to a local variable named curcontext to inform other functions
that look for styles of the context in which they are being invoked.

To put this together, you'd simply do something like:

local curcontext="${curcontext%:*:*}:darwinup"
_files -g '*.(cpio|tar|xar)'

Then a user can write

zstyle ':completion:*:darwinup' file-patterns "%p *.cpgz”

where %p will be replaced by your defaults and *.cpgz will also be
tried (see previous remarks about why spaces are complicated).



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