zsh-users
 help / color / mirror / code / Atom feed
From: dana <dana@dana.is>
To: Chris Nebel <c.nebel@mac.com>
Cc: zsh-users@zsh.org
Subject: Re: Grouping and ordering completions with zshcompsys?
Date: Mon, 21 Oct 2019 03:51:22 -0500	[thread overview]
Message-ID: <A00D955D-D4B7-4854-B357-D28D185DC69A@dana.is> (raw)
In-Reply-To: <4E66F85B-02CC-4F77-A409-5E9C8E21F467@mac.com>

On 21 Oct 2019, at 01:57, Chris Nebel <c.nebel@mac.com> wrote:
> Notice the two distinct groups with names, and the serial numbers appearing
> before the names.  For bonus points, I’d like the exclusion behavior that
> “_arguments” has, so it won’t complete the same archive more than once, and
> if the user already typed “all” it won’t complete anything more.  The
> closest I’ve managed to get this this:

Grouping is usually something you leave up to the user's group-name style. If
they have zsh configured to keep groups separate, they will get that
behaviour. If they don't, they won't. It's possible to force the issue in an
individual completion function, but i think generally you're meant to assume
that it's configured how they want it.

For putting the serial numbers in the names, you can make use of the name2
argument to _describe, like this (just to illustrate the basic concept):

  name1=( {'1  omg','2  zomg','4  bbq','42 foobar'}.tgz )
  name2=( ${(@)name1##[0-9\ ]##} )
  _describe -2Vt archives archive name1 name2

When you add descriptions (to name1), though, it seems to ignore -12JVo and
just put the matches in some random order. I don't understand why, and i can't
look into it right now. Maybe it's expected.

To separate out the meta-archives, i guess just use _alternative:

  _alternative \
    'archives: :_foo_archives' \
    'meta-archives: :_foo_meta_archives'

Where _foo_archives and _foo_meta_archives are your helper functions that
handle completion for those particular matches.

For handling the `all` meta-archive, you can just check to see if `all` is in
$line or $words before deciding how to proceed (again, just to illustrate,
you probably wouldn't do it *exactly* like this):

  if (( $line[(I)all] )); then
    _message 'no more archives'
  else
    _alternative ...
  fi

On 21 Oct 2019, at 02:02, Chris Nebel <c.nebel@mac.com> wrote:
> Related question: is there a way to get _files to only complete files that
> pass a test of some sort?  Specifically, I want files that are in one of
> four (possibly compressed) archive formats.

Usually you give it a pattern that matches file extensions with -g, as in:

  _files -g '*.(tgz|txz|...)(#q-.)'

If you can't get the information you need with globbing, there are ways to be
more clever about it, but that's not a super common thing to do.

dana


      reply	other threads:[~2019-10-21  8:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-21  6:57 Chris Nebel
2019-10-21  7:02 ` Chris Nebel
2019-10-21  8:51   ` dana [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=A00D955D-D4B7-4854-B357-D28D185DC69A@dana.is \
    --to=dana@dana.is \
    --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).