1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-02 10:01:11 +02:00

48513: Let extra-verbose completion show parameter values

This commit is contained in:
Marlon Richert 2021-04-12 23:17:23 +03:00 committed by Oliver Kiddle
parent 28cf6bd111
commit 587cced35d
3 changed files with 62 additions and 15 deletions

View file

@ -1,5 +1,9 @@
2021-04-16 Oliver Kiddle <opk@zsh.org>
* Marlon Richert: 48513: Completion/Zsh/Type/_parameters,
Test/Y01completion.ztst: Let extra-verbose completion
show parameter values
* unposted: Etc/BUGS: update on bug list
* 48556: Completion/BSD/Command/_ipfw: new completion

View file

@ -6,18 +6,39 @@
# If you specify a -g option with a pattern, the pattern will be used to
# restrict the type of parameters matched.
local expl pattern fakes faked tmp i pfilt
if compset -P '*:'; then
_history_modifiers p
return
fi
pattern=(-g \*)
local MATCH i pfilt
local -i MBEGIN MEND nm=$compstate[nmatches]
local -a expl pattern=(-g \*) normal described verbose faked fakes tmp
zstyle -t ":completion:${curcontext}:parameters" prefix-needed &&
[[ $PREFIX != [_.]* ]] &&
pfilt='[^_.]'
_description parameters expl parameter
zparseopts -D -K -E g:=pattern
fakes=()
faked=()
if zstyle -t ":completion:${curcontext}:parameters" extra-verbose; then
described=(
"${(@M)${(@k)parameters[(R)$~pattern[2]~*(hideval|local|special)*]}:#$~pfilt*}"
)
compadd "$@" "$expl[@]" -D described -a - described
if (( $#described )); then
verbose=(
${described[@]:/(#m)*/"${MATCH}:${(@q+)${(Pkv@q+)MATCH}//\\/\\\\}"} )
_describe -t parameters parameter verbose "$@" "$expl[@]"
fi
normal=(
"${(@M)${(@k)parameters[(R)$~pattern[2]~^(*(hideval|special)*)~*local*]}:#$~pfilt*}"
)
else
normal=( "${(@M)${(@k)parameters[(R)$~pattern[2]~*local*]}:#$~pfilt*}" )
fi
if zstyle -a ":completion:${curcontext}:" fake-parameters tmp; then
for i in "$tmp[@]"; do
if [[ "$i" = *:* ]]; then
@ -27,13 +48,8 @@ if zstyle -a ":completion:${curcontext}:" fake-parameters tmp; then
fi
done
fi
compadd "$@" "$expl[@]" - "$normal[@]" "${(@)fakes:|described}" \
"${(@)${(@)${(@M)faked:#${~pattern[2]}}%%:*}:|described}"
zstyle -t ":completion:${curcontext}:parameters" prefix-needed && \
[[ $PREFIX != [_.]* ]] && \
pfilt='[^_.]'
_wanted parameters expl parameter \
compadd "$@" -Q - \
"${(@M)${(@k)parameters[(R)${pattern[2]}~*local*]}:#${~pfilt}*}" \
"$fakes[@]" \
"${(@)${(@M)faked:#${~pattern[2]}}%%:*}"
(( compstate[nmatches] > nm ))
return 0

View file

@ -240,7 +240,7 @@ F:regression test workers/31611
comptesteval "zstyle ':completion:*:tst:*' ignored-patterns 2"
comptest $'tst 1,\t'
comptesteval "zstyle -d ':completion:*:tst:*' ignored-patterns"
0:-F doesn't break _sequence
0:-F does not break _sequence
>line: {tst 1,}{}
>DESCRIPTION:{desc}
>NO:{2}
@ -255,6 +255,33 @@ F:regression test workers/31611
>FI:{file1}
>FI:{file2}
comptesteval "bar=({$'\\0'..$'\\C-?'}); baz=\$bar"
comptesteval 'zstyle ":completion:*:parameters" extra-verbose yes'
comptesteval 'zstyle ":completion:*" fake-parameters bar baz:array'
comptest $': $ba\t'
0:extra-verbose shows parameter values
>line: {: $ba}{}
>DESCRIPTION:{parameter}
>NO:{bar -- '^@' '^A' '^B' '^C' '^D' '^E' '^F' '^G' '^H' '\t' '\n' '^K' '^L' '^M}
>NO:{baz -- '^@ ^A ^B ^C ^D ^E ^F ^G ^H \t \n ^K ^L ^M ^N ^O ^P ^Q ^R ^S ^T ^U ^}
comptesteval "path=( $ZTST_srcdir:A )"
comptesteval 'typeset -H paths=HIDDEN'
comptest $': $path\t'
0:extra-verbose doesn't show special or hidden parameter values
>line: {: $path}{}
>DESCRIPTION:{parameter}
>NO:{path}
>NO:{paths}
comptesteval 'zstyle -d ":completion:*:parameters" extra-verbose'
comptest $': $ba\t'
0:parameter values not shown without extra-verbose
>line: {: $ba}{}
>DESCRIPTION:{parameter}
>NO:{bar}
>NO:{baz}
comptesteval '_tst() { local disp=( {a..z} ); compadd -ld disp $disp[@]; comppostfuncs=( _pst ) }'
comptesteval '_pst() { local disp=( "<INSERT>$compstate[insert]</INSERT>" ); compadd -Qld disp $disp }'
comptesteval "zstyle ':completion:*' menu select=long-list"