From: Felipe Contreras <felipe.contreras@gmail.com>
To: Ray Andrews <rayandrews@eastlink.ca>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: completion within a function
Date: Wed, 30 Dec 2020 11:21:46 -0600 [thread overview]
Message-ID: <CAMP44s13tqgmNgUcuAxUJyJ_LGjDSEE1FJ64k2r12UogbW0r0w@mail.gmail.com> (raw)
In-Reply-To: <f490bbd8-dc96-341d-e11b-a5d957c9268e@eastlink.ca>
On Wed, Dec 30, 2020 at 10:45 AM Ray Andrews <rayandrews@eastlink.ca> wrote:
> So the idea of invoking completion within a function is now a matter of
> curiosity only. Still I'm surprised it can't be done. It's one of
> those things where zsh smartness is hard to turn off.
I can be done, it's just not straight-forward.
After removing all the unnecessary stuff from the tests, I came up
with this script that does list completions:
./complete "git --"
#!/bin/zsh
zmodload zsh/zpty
dir=$(mktemp -d)
cat > "$dir/.zshrc" <<'EOF'
setopt zle
setopt list_rows_first
LC_ALL=C
PS1="<PROMPT>"
TERM=dumb
fpath=($ZDOTDIR $fpath)
LISTMAX=1000 # There seems to be a bug in zsh with several thousands
autoload -U compinit && compinit -u
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
bindkey "^I" zle_complete
EOF
zpty zsh "ZDOTDIR=$dir zsh"
zpty -n -w zsh "$1"$'\t'
zpty -r zsh log '*<END-CHOICES>'
for x in ${(M)${(f)log}:#*'<LC><NO>'*}; do
print -- "${${x%'<EC>'*}#*'<RC>'}"
done
rm -r "$dir"
--
Felipe Contreras
next prev parent reply other threads:[~2020-12-30 17:22 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-29 15:24 Ray Andrews
2020-12-29 18:52 ` Bart Schaefer
2020-12-29 19:36 ` Felipe Contreras
2020-12-29 19:41 ` Roman Perepelitsa
2020-12-29 21:04 ` Ray Andrews
2020-12-29 21:21 ` Ray Andrews
2020-12-29 22:03 ` Bart Schaefer
2020-12-29 21:48 ` Bart Schaefer
2020-12-30 0:31 ` Ray Andrews
2020-12-30 4:34 ` Roman Perepelitsa
2020-12-30 16:45 ` Ray Andrews
2020-12-30 17:21 ` Felipe Contreras [this message]
2020-12-30 20:43 ` Bart Schaefer
2020-12-30 20:46 ` Bart Schaefer
2020-12-30 20:50 ` Ray Andrews
2020-12-30 21:31 ` Roman Perepelitsa
2020-12-30 22:05 ` Bart Schaefer
2020-12-30 22:18 ` Felipe Contreras
2020-12-30 23:47 ` Bart Schaefer
2020-12-31 0:08 ` Bart Schaefer
2020-12-31 0:12 ` Felipe Contreras
2020-12-31 0:30 ` Bart Schaefer
2020-12-31 0:39 ` Bart Schaefer
2020-12-31 1:04 ` Felipe Contreras
2020-12-31 21:25 ` Bart Schaefer
2021-01-01 0:12 ` Ray Andrews
2021-01-02 0:27 ` Bart Schaefer
2021-01-02 22:24 ` Bart Schaefer
2021-01-03 0:28 ` Felipe Contreras
2021-01-03 0:53 ` Bart Schaefer
2021-01-03 1:20 ` Felipe Contreras
2021-01-03 2:21 ` Bart Schaefer
2021-01-03 2:47 ` Felipe Contreras
2021-01-03 3:30 ` Bart Schaefer
2021-01-03 23:16 ` Felipe Contreras
2021-01-05 19:57 ` Bart Schaefer
2021-01-03 17:50 ` Bart Schaefer
2021-01-03 0:07 ` Felipe Contreras
2020-12-31 1:03 ` Felipe Contreras
2020-12-30 6:45 ` Bart Schaefer
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=CAMP44s13tqgmNgUcuAxUJyJ_LGjDSEE1FJ64k2r12UogbW0r0w@mail.gmail.com \
--to=felipe.contreras@gmail.com \
--cc=rayandrews@eastlink.ca \
--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).