From: Bart Schaefer <schaefer@brasslantern.com>
To: Felipe Contreras <felipe.contreras@gmail.com>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: completion within a function
Date: Thu, 31 Dec 2020 13:25:47 -0800 [thread overview]
Message-ID: <CAH+w=7bnFjxfriMt-BVau66A3OZGUdKcbCDXX8G3pD_i=_+kTQ@mail.gmail.com> (raw)
In-Reply-To: <CAMP44s3LE2ccjgB9mxjZNifUX0evDhgUSh9oWpNM3GDgM0DwVQ@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1081 bytes --]
On Wed, Dec 30, 2020 at 5:04 PM Felipe Contreras
<felipe.contreras@gmail.com> wrote:
>
> With that I do see the output. There's some garbage in it, but it works.
I'm curious what the garbage is? Maybe something needs redirection.
Attached (to prevent gmail line wrapping) is a still-fragmentary and
undocumented source-able implementation.
* It works better to discard compstate[vared] than to muck with _comps[-vared-]
* Uses a restricted keymap to avoid messing with the main keymap.
* Some names "protected" with double-underscore as in zed.
* Included a debug function although it's a bit knobbly.
At an interactive command-line, you can type e.g.
run-complete git --
to see what the completion might be. I wonder about attaching this to
something ala run-help.
However, that doesn't work if output is redirected anywhere. If you
want to pipe it or put it in a command substitution, you have to use
e.g.
complete git -- | less
or
guesses=( $(complete git --) )
Also, each word has to be individually quoted, you won't get useful results from
complete "git --"
[-- Attachment #2: complete.txt --]
[-- Type: text/plain, Size: 1315 bytes --]
#autoload
(( $+_comps )) || { autoload -U compinit; compinit -i -D }
zmodload zsh/zpty
if ! bindkey -M __complete 2>/dev/null
then
bindkey -N __complete
zle -C __complete_all complete-word _generic
zstyle ':completion:__complete_all::::' completer _all_matches _complete
zstyle ':completion:__complete_all:*' insert true
bindkey -M __complete '^Xa' __complete_all
# bindkey -M __complete '^X?' _complete_debug
bindkey -M __complete $'\n' .accept-line
# bindkey -M __complete '^G' .send-break
__init_complete() { zle -U $'\Cxa\n' }
zle -N __init_complete
fi
completion-context() {
if (( debug )); then
print -u $debug -C 2 -a -r \
CONTEXT: ":completion:$curcontext" \
STATE: '' "${(@kv)compstate}"
fi
}
hide-vared() { compstate[vared]='' }
run-complete () {
local -a compprefuncs=(hide-vared "${(@)compprefuncs}")
vared -M __complete -i __init_complete ${${argv:+argv}:-reply}
}
debug-complete() {
local -i debug
local -a compprefuncs=(completion-context "${(@)compprefuncs}")
local -a comppostfuncs=("${(@)comppostfuncs}" completion-context)
exec {debug}>&2
complete "$@"
exec {debug}>&-
}
complete() {
local -a reply=( "$@" )
zpty complete-tty run-complete
{ zpty -r complete-tty } always { zpty -d complete-tty }
}
(( ARGC )) && complete "$@"
next prev parent reply other threads:[~2020-12-31 21:26 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
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 [this message]
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='CAH+w=7bnFjxfriMt-BVau66A3OZGUdKcbCDXX8G3pD_i=_+kTQ@mail.gmail.com' \
--to=schaefer@brasslantern.com \
--cc=felipe.contreras@gmail.com \
--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).