Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
_values with controllable duplicates suppression?
- X-seq: zsh-users 26580
- From: Phil Pennock <zsh-workers+phil.pennock@xxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: _values with controllable duplicates suppression?
- Date: Thu, 18 Mar 2021 19:40:24 -0400
- Archived-at: <https://zsh.org/users/26580>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-users/2021-03/YFPk6CEytUy%2F3FXI%40fullerene.field.pennock-tech.net>
- List-id: <zsh-users.zsh.org>
- Openpgp: url=https://www.security.spodhuis.org/PGP/keys/keys-2013rsa-2020cv25519.asc
My completion-fu is failing me once more and I would like some guidance
on how to handle supplying completions, where currently I use
`_values -w`.
I have a custom `git grab` which has various heuristics and ultimately
lets me do `git grab -o orgname repo1 repo2 repo3`. I have
tab-completion for this and it mostly works, and has for a long time.
The completion caches the results of using the GitHub API for a given
org/user, using appropriate keying into an associative array var, so
that if I hit tab multiple times there's only one remote API call until
a half hour passes and the cached data is invalidated.
I will be creating entries in the current directory, so have:
already=(*(D-/))
and then call, when the cache is already populated:
candidates=(${(o)=_github_repos_byowner[$cache_key]})
_values -w "uncloned github repositories for $identifier" "${(@)candidates:|already}"
and ultimately the flow for when the cache needs to be populated ends up
with the same _values call.
The top level is:
_arguments -C -s [options stuff] '*:REPO:_github_repos_for'
I really like the way that `_values -w` means that if I have already put
a given repo onto the command-line, it's not offered again.
My problem is that sometimes there's an organization with the same name
as one of the repos inside that organization. Eg, "foo/foo" as well as
"foo/bar", "foo/baz", so if I do:
git grab -o foo <TAB>
then the "foo" result is suppressed because `_values -w` sees that `foo`
is already on the command-line, and I'm only offered `bar` and `baz`.
Is there any way (context shift, something else?) to track from
_arguments which word is the start of the `*:REPO:...` completion point
and constrain _values (or equivalent) to only suppress duplicate words
which appear from that point onwards?
Thanks,
-Phil
Messages sorted by:
Reverse Date,
Date,
Thread,
Author