* _values with controllable duplicates suppression?
@ 2021-03-18 23:40 Phil Pennock
2021-03-19 2:40 ` Oliver Kiddle
0 siblings, 1 reply; 2+ messages in thread
From: Phil Pennock @ 2021-03-18 23:40 UTC (permalink / raw)
To: zsh-users
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: _values with controllable duplicates suppression?
2021-03-18 23:40 _values with controllable duplicates suppression? Phil Pennock
@ 2021-03-19 2:40 ` Oliver Kiddle
0 siblings, 0 replies; 2+ messages in thread
From: Oliver Kiddle @ 2021-03-19 2:40 UTC (permalink / raw)
To: Phil Pennock; +Cc: zsh-users
Phil Pennock wrote:
> 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.
I wouldn't use _values just for that feature. Try passing -F words (or
-F line if using _arguments) to compadd.
> 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`.
It is ignoring the contents of the $words array so you can manipulate
that (plus $CURRENT) to only cover the final arguments. Actually,
it is probably using $words[2,-1]. You can use two colons after the
asterisk in the _arguments spec to strip down the words array:
'*::repo:_github_repos_for'
You may be better off with '*:::repo:= _github_repos_for' actually.
Depends how many normal arguments there are. That sets $words to
only those covered by this spec and then the = makes it add a fake
one for the command-position.
Oliver
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-03-19 2:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-18 23:40 _values with controllable duplicates suppression? Phil Pennock
2021-03-19 2:40 ` Oliver Kiddle
zsh-users
This inbox may be cloned and mirrored by anyone:
git clone --mirror http://inbox.vuxu.org/zsh-users
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V1 zsh-users zsh-users/ http://inbox.vuxu.org/zsh-users \
zsh-users@zsh.org
public-inbox-index zsh-users
Example config snippet for mirrors.
Newsgroup available over NNTP:
nntp://inbox.vuxu.org/vuxu.archive.zsh.users
code repositories for the project(s) associated with this inbox:
https://git.vuxu.org/mirror/zsh/
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git