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

Re: Grouping and ordering completions with zshcompsys?



On 21 Oct 2019, at 01:57, Chris Nebel <c.nebel@xxxxxxx> 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@xxxxxxx> 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



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