Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Grouping and ordering completions with zshcompsys?
- X-seq: zsh-users 24370
- From: Chris Nebel <c.nebel@xxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Grouping and ordering completions with zshcompsys?
- Date: Sun, 20 Oct 2019 23:57:53 -0700
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mac.com; s=1a1hai; t=1571641075; bh=2F8XNJfsXgNS80tpF2pKJx5qlSzgHUy6XkPrLKKxYdg=; h=From:Content-Type:Subject:Message-Id:Date:To; b=LfIAzH2zT9Wz2RFOkyZH94jqzF0hW8XUGzz1dXC+V039x71YERwJRC4kdIiRnVJxx HJOwoXmkIMEkQAYQMchHkQtMon5ZBKx7R2FXdQIyM8BMoGGcvXH36dxskSa16yLbX3 nszh1NmDw3kQY1aOWV1hWSZn2vRjYP1HbPT1g8xa10mJESBQm1gBx+5THjlz7ZJ/m5 xMhX96eqzFhIkdv6veqyLBBRbUe7pHE075JlOo9VBpYQFfl4umsk6gplWay6WlaQNj WlVo6SbDrEGT8ALc6s+yAZetKj0v6ovxJwT0OecVnu5xx/ibVwcivxadWgKuQ7oswD ELeChNt7hjuDg==
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
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