* Get completions from a script
@ 2022-09-09 2:59 Felipe Contreras
0 siblings, 0 replies; only message in thread
From: Felipe Contreras @ 2022-09-09 2:59 UTC (permalink / raw)
To: Zsh Users, Zsh hackers list, Bart Schaefer
Hi,
I finally finished working on the script to generate completions based
on some hypothetically typed characters.
For example:
complete 'git s'
This comes from a discussion in zsh-users [1] in 2021 where different
methods were suggested.
The problem with using the complete-word approach is that it generates
prefixes that I don't want, for example given this:
_foobar() {
compset -P '*[=:]'
compadd octopus ours recursive resolve subtree
}
compdef _foobar foobar
I would expect `complete 'git -s=re'` to only return "recursive", not
"-s=recursive".
The idea to use vared did actually work, and with that I'm able to get
rid of the separate file and to put everything in a single file of 29
lines.
Here it is:
zmodload zsh/zpty
autoload -U compinit && compinit -u
setopt list_rows_first
LISTMAX=1000
zstyle ":completion:*:default" list-colors "no=<NO>" "fi=<NO>"
"di=<NO>" "sp=<SP>" "lc=<LC>" "rc=<RC>" "ec=<EC>\n"
zstyle ':completion:*' verbose no
zle_complete() {
zle list-choices
zle kill-whole-line
print "<END-CHOICES>"
}
zle -N zle_complete
hide-vared() { compstate[vared]=''; }
run_complete() {
local -a compprefuncs=(hide-vared "${(@)compprefuncs}")
local cmd="$1"
vared -i zle_complete cmd
}
zpty c "run_complete \"$1\""
zpty -r c log '*<END-CHOICES>'
zpty -d c
for x in ${(M)${(f)log}:#*'<LC><NO>'*}; do
print -- "${${x%'<EC>'*}#*'<RC>'}"
done
Cheers.
[1] https://www.zsh.org/users/26334
--
Felipe Contreras
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-09-09 3:03 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-09 2:59 Get completions from a script Felipe Contreras
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).