zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Chris Nebel <c.nebel@mac.com>
Cc: zsh-users <zsh-users@zsh.org>
Subject: Re: Use of (e:...:) glob qualifier with _files -g?
Date: Mon, 4 Nov 2019 15:24:32 -0600	[thread overview]
Message-ID: <CAH+w=7bmp_HRxgeUitLnbFPvpwOYrdTekEGa33Ok0Av=AEYRcg@mail.gmail.com> (raw)
In-Reply-To: <23662F36-B0E7-43FE-81AF-86C2C9D03044@mac.com>

On Mon, Nov 4, 2019 at 2:42 PM Chris Nebel <c.nebel@mac.com> 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).

      parent reply	other threads:[~2019-11-04 21:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-04  6:08 Chris Nebel
2019-11-04  6:56 ` dana
2019-11-04 20:41   ` Chris Nebel
2019-11-04 20:50     ` Chris Nebel
2019-11-04 21:24     ` Bart Schaefer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH+w=7bmp_HRxgeUitLnbFPvpwOYrdTekEGa33Ok0Av=AEYRcg@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=c.nebel@mac.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).