From: Phil Pennock <zsh-workers+phil.pennock@spodhuis.org>
To: zsh-users@zsh.org
Subject: _values with controllable duplicates suppression?
Date: Thu, 18 Mar 2021 19:40:24 -0400 [thread overview]
Message-ID: <YFPk6CEytUy/3FXI@fullerene.field.pennock-tech.net> (raw)
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
next reply other threads:[~2021-03-18 23:41 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-18 23:40 Phil Pennock [this message]
2021-03-19 2:40 ` Oliver Kiddle
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YFPk6CEytUy/3FXI@fullerene.field.pennock-tech.net \
--to=zsh-workers+phil.pennock@spodhuis.org \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).