Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: completion within a function
- X-seq: zsh-users 26302
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: completion within a function
- Date: Sat, 2 Jan 2021 14:24:49 -0800
- Archived-at: <https://zsh.org/users/26302>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-users/2021-01/CAH%2Bw%3D7adMRpgA97%3DY-m_U--HW0APgVH3Bq4Y3%3DZjy9uoh_7fzg%40mail.gmail.com>
- In-reply-to: <CAH+w=7bZXGvVqeftVn4FnPd+G9Y5tm+YU6yV9wkgE1vXTEVLKw@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- References: <c9416d92-29b1-68e5-e51e-d7152f1fbc4b@eastlink.ca> <CAH+w=7bT5GaGvWih=A8KCyUe4N6k25VxDLcpPA5C1yGn38Zimg@mail.gmail.com> <819ec6fe-5af2-2e97-c5bb-f434b1de86d7@eastlink.ca> <CAH+w=7bSbhdHGC89daK+8o0psLhdw969=GviC4s554t37_zrDw@mail.gmail.com> <520ce98a-4394-726d-3d12-8ef414e881c9@eastlink.ca> <CAN=4vMquijkmnETv2xUdnpGcJoQPaimXT1+i+daHoivLmpK+TA@mail.gmail.com> <f490bbd8-dc96-341d-e11b-a5d957c9268e@eastlink.ca> <CAMP44s13tqgmNgUcuAxUJyJ_LGjDSEE1FJ64k2r12UogbW0r0w@mail.gmail.com> <CAH+w=7a+9_jX8xkvKjCVhQWXQMqQkWvahHyzTj=Lm_DgC=o5kw@mail.gmail.com> <CAMP44s1KT0B-wGmEndZUW2xkh8t-mawKA3y5yaqAH3GjiEXuCA@mail.gmail.com> <CAH+w=7ZqpLfuoqdJ1yRRDR37DHLK5oOQP+878yaWA+M119QdhA@mail.gmail.com> <CAMP44s3qy8OToPuV9DH2fnU=eDYuZYFGmvoDUdmexdCYC_FpSg@mail.gmail.com> <CAH+w=7ZYcLH0DhnDMTGGKE1VFCVT15K0RFpDbQvZH_EvD1ywHg@mail.gmail.com> <CAH+w=7bL1RodoTiNQykLESwK5v3ppGYs_AG-bGcgPqnf-kC_Cw@mail.gmail.com> <CAMP44s3LE2ccjgB9mxjZNifUX0evDhgUSh9oWpNM3GDgM0DwVQ@mail.gmail.com> <CAH+w=7bnFjxfriMt-BVau66A3OZGUdKcbCDXX8G3pD_i=_+kTQ@mail.gmail.com> <CAH+w=7bZXGvVqeftVn4FnPd+G9Y5tm+YU6yV9wkgE1vXTEVLKw@mail.gmail.com>
On Fri, Jan 1, 2021 at 4:27 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> Ahh ... because it's zpty, the cursor movements get captured along
> with everything else.
How about this?
ubuntu% complete git --
--bare
--exec-path
--git-dir
--help
--html-path
--info-path
--literal-pathspecs
--man-path
--namespace
--no-pager
--no-replace-objects
--paginate
--version
--work-tree
Earlier, Felipe wrote:
> LISTMAX=1000 # There seems to be a bug in zsh with several thousands
Could this be happening because "zpty -r" will only return up to one
megabyte of output? If not, what's the symptom of the bug?
#autoload
# Usage: complete commandline
#
# where "commandline" is one or more words, of which the last is the
# prefix of the desired completion. Thus:
# complete g
# completes all commands whose name starts with "g"
# complete git --
# completes all options of "git" that begin with two hyphens
# complete ls c
# completes all files in $PWD having names starting with "c"
#
# All possible completions are returned, one per line. There is a
# limit of approximately half a megabyte of total output, as a side-
# effect of vared plus the limit of one megabyte per "zpty -r".
(( $+_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}
(( ARGC )) || print -nrl -- "~~~${(@)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() {
(( ARGC )) || return 1
local REPLY reply=( "$@" )
zpty complete-tty run-complete
{
zpty -r complete-tty REPLY $'*~~~*~~~'
} always {
zpty -d complete-tty
}
reply=( "${(@)${(f)${${REPLY%~~~}#*~~~}}%$'\r'}" )
shift $((ARGC-1)) reply
print -lr -- "${(@)reply}"
}
(( ARGC )) && complete "$@"
Messages sorted by:
Reverse Date,
Date,
Thread,
Author