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

Re: Grouping and ordering completions with zshcompsys?

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.  I can get a thumbs-up/thumbs-down decision using file(1), but I don’t see how to communicate that to _files.

> On Oct 20, 2019, at 11:57 PM, Chris Nebel <c.nebel@xxxxxxx> wrote:
> zsh-users—
> I’ve been fiddling with a zsh completion function for darwinup(1), partly as a learning exercise, partly because I wanted one.  (I’m aware of <https://github.com/tetsuok/darwinup-zsh-completion>, but it’s not as smart as I wanted, and learning exercise.)  For the most part I’ve got it working, but I’m struggling with grouping and ordering.
> For background, darwinup(1) manages installed “archives” — it’s basically a simple package manager — and if you ask for a list of what’s installed, you get something like this:
> Serial UUID                                  Date          Build    Name
> ====== ====================================  ============  =======  =================
> 1      6F5662BD-4D69-470E-B708-3D0F3706D0A6  Sep 20 00:16  18A396   omg.tgz
> 2      CB732989-ACB4-49B4-B49C-64F40EF2B17B  Sep 22 00:16  17A42    zomg.tgz
> 4      C2AF0BF1-9FA3-4EE7-A402-32CDBCDA0F8C  Sep 23 00:18  18F205   bbq.tgz
> 42     52FC4789-769C-4CD8-A39B-D1B6CC0B2009  Oct 01 12:34  18F205   foobar.tgz
> darwinup has various sub-commands which take archives as arguments, which can be specified by “serial”, UUID, or name, so I’d like to complete the serial number or name.  Additionally, there are four meta-names: “all”, “newest”, “oldest”, and “superseded”, which should also be completable.
> Merely providing all those as completion options is easy — what I haven’t been able to do is get them listed the way I want, which is something like this:
>> archives
>> 1      omg.tgz   -- installed on 18A396 at Oct 15 00:16
>> 2      zomg.tgz  -- installed on 17A42 at Oct 19 00:16  
>> 4      bbq.tgz -- installed on 18F205 at Oct 20 00:18
>> 42     foobar.tgz -- installed on 18F205 at Oct 20 00:19
>> meta-archives
>> all -- all archives
>> newest -- most recently installed archive
>> oldest -- least recently installed archive
>> superseded -- all archives replaced by other archives
> 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:
> omg.tgz     1  -- installed on 18A396 at Oct 15 00:16
> zomg.tgz    2  -- installed on 17A42 at Oct 19 00:16  
> bbq.tgz      4  -- installed on 18F205 at Oct 20 00:18
> foobar.tgz   42 -- installed on 18F205 at Oct 20 00:19
> all     newest     oldest     superseded
> I can get force the meta-archive names to appear together at the end by not giving them descriptions, but then they don’t have descriptions.  I got the regular archives to sort in numeric order by ordering them myself and using “_describe -V”, but then I lose the exclusions, and everything I’ve tried so far puts the serial numbers *after* the names.  It’s not terrible, but I’m at a loss for how to do better.  An example would help, but I haven’t yet found an existing command that does anything like this.  Any pointers?
> —Chris N.

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