Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: _arguments '(-o --option)'[...] functionality without calling _arguments
- X-seq: zsh-users 29244
- From: Oliver Kiddle <opk@xxxxxxx>
- To: Adam Szkoda <adaszko@xxxxxxxxx>
- Cc: zsh-users@xxxxxxx
- Subject: Re: _arguments '(-o --option)'[...] functionality without calling _arguments
- Date: Wed, 13 Sep 2023 13:41:47 +0200
- Archived-at: <https://zsh.org/users/29244>
- In-reply-to: <CAEroKaiTZUbp_o+Vn_puXc3uxqksOM5BR=gAyq935y82ssOAxQ@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- References: <CAEroKaiTZUbp_o+Vn_puXc3uxqksOM5BR=gAyq935y82ssOAxQ@mail.gmail.com>
Adam Szkoda wrote:
> Rust's cargo completion script has this line in it: _arguments '(-p --package)'
> {-p+,--package=}'[specify package to build]:package:_cargo_package_names'
>
> This results in very nice and compact completions where --package and -p are
> grouped in a single line and share the same description, yet each of them can
> be selected separately. This is great.
>
> Yet I can't find the code in _arguments that's responsible for this. I'm
> suspecting it's delegating to the comparguments builtin ([1])?
_describe does the same thing for words that are not options. It's
implementation is in C code that is shared with that used by
comparguments. It doesn't have to be done in C, however - compadd's
interface would allow you to achieve the same thing from shell code if
you wanted but that is more involved so check whether _describe meets
your needs first.
If you're looking at other completion functions for inspiration, I would
recommend looking at those that come with zsh rather than those other
projects include. Cargo's is fairly good but external projects often
include completions that are auto-generated, converted from bash or
otherwise less well written.
Oliver
Messages sorted by:
Reverse Date,
Date,
Thread,
Author