39479 + 39481 minus _path_files hunk (see 39489): Completion: audit 'compset -P' calls to use shortest match where applicable, plus random drive-by tweaks.

Found by grepping for patterns that can match needles of various lengths:

    :grep 'compset -[PS].*[\#^*()\|<>?~\]' Completion/
This commit is contained in:
Daniel Shahaf 2016-09-28 17:46:37 +00:00
parent a96e34b459
commit 7ad0001183
32 changed files with 77 additions and 42 deletions

View file

@ -1,3 +1,28 @@
2016-10-07 Daniel Shahaf <d.s@daniel.shahaf.name>
* 39479 + 39481 minus _path_files hunk (see
39489): Completion/Debian/Command/_debfoster,
Completion/Linux/Command/_modutils,
Completion/Redhat/Command/_rpm, Completion/Unix/Command/_ant,
Completion/Unix/Command/_cpio, Completion/Unix/Command/_cvs,
Completion/Unix/Command/_dbus, Completion/Unix/Command/_git,
Completion/Unix/Command/_graphicsmagick,
Completion/Unix/Command/_growisofs, Completion/Unix/Command/_gs,
Completion/Unix/Command/_gsettings,
Completion/Unix/Command/_head,
Completion/Unix/Command/_imagemagick,
Completion/Unix/Command/_java, Completion/Unix/Command/_lp,
Completion/Unix/Command/_lzop, Completion/Unix/Command/_mount,
Completion/Unix/Command/_perl, Completion/Unix/Command/_php,
Completion/Unix/Command/_rlogin, Completion/Unix/Command/_ssh,
Completion/Unix/Command/_tail, Completion/Unix/Command/_w3m,
Completion/X/Command/_rdesktop, Completion/X/Command/_x_utils,
Completion/Zsh/Command/_fc, Completion/Zsh/Type/_arrays,
Completion/Zsh/Type/_globflags, Completion/Zsh/Type/_ps1234,
Completion/Zsh/Type/_vars: Completion: audit 'compset -P'
calls to use shortest match where applicable, plus random
drive-by tweaks.
2016-10-06 Peter Stephenson <p.stephenson@samsung.com>
* Julien Cretin: 39579: Src/subst.c: position of \0

View file

@ -26,10 +26,10 @@ _arguments -C \
&& ret=0
if [[ -n "$state" ]]; then
if compset -P '*='; then
if compset -P 1 '*='; then
case "$IPREFIX" in
*(#i)(install|remove|info)cmd*)
_wanted values expl 'command string' _command && ret=0
_wanted values expl 'command string' _cmdstring && ret=0
;;
*(#i)(keeperfile|dpkg(status|available))*)
_wanted values expl 'metadata file' _files && ret=0

View file

@ -123,7 +123,7 @@ _modutils() {
;;
params)
if compset -P '*='; then
if compset -P 1 '*='; then
_message -e value 'parameter value'
else
local params

View file

@ -298,7 +298,7 @@ _rpm () {
${(f)"$(_call_program capabilities rpm -qa --queryformat '%\{requirename}\\n' 2>/dev/null)"} && ret=0
;;
relocate)
if compset -P '*='; then
if compset -P 1 '*='; then
_description directories expl 'new path'
else
_description directories expl 'old path'

View file

@ -83,7 +83,7 @@ case $state in
"classpath:$state:_path_files -r': ' -/" && ret=0
;;
property)
if compset -P '*='; then
if compset -P 1 '*='; then
_default && ret=0
else
_message -e properties 'property name'

View file

@ -106,10 +106,10 @@ fi
_arguments -C -s "$args[@]" && ret=0
if [[ $state = afile ]]; then
if compset -P '*:'; then
# TODO: doesn't need to be rsh.
_wanted files expl 'remote files' \
compadd $(rsh ${words[CURRENT]%:*} echo ${words[CURRENT]#*:}\*) && ret=0
if [[ $ig != gnu ]]; then
_files && ret=0
elif compset -P 1 '*:'; then
_remote_files -- ssh && ret=0
elif compset -P '*@'; then
_wanted hosts expl 'remote host name' _hosts && ret=0
else

View file

@ -595,7 +595,7 @@ _cvs_tempdir() {
(( $+functions[_cvs_user_variable] )) ||
_cvs_user_variable() {
if compset -P '*='; then
if compset -P 1 '*='; then
_default
else
_message -e variables "variable"

View file

@ -32,7 +32,7 @@ esac
case $state in
addresses)
compset -P '*;'
if compset -P '*='; then
if compset -P 1 '*='; then
_files && ret=0
else
_message -e addresses address

View file

@ -1335,7 +1335,7 @@ _git-push () {
'--follow-tags[also push missing annotated tags reachable from the pushed refs]' \
'(--receive-pack --exec)'{--receive-pack=-,--exec=-}'[path to git-receive-pack on remote]:remote git-receive-pack:_files' \
'(--force-with-lease --no-force-with-lease)*--force-with-lease=-[allow refs that are not ancestors to be updated if current ref matches expected value]::ref and expectation:->lease' \
'(--force-with-lease --no-force-with-lease)--no-force-with-lease=-[cancel all previous force-with-lease specifications]' \
'(--force-with-lease --no-force-with-lease)--no-force-with-lease[cancel all previous force-with-lease specifications]' \
'(-f --force)'{-f,--force}'[allow refs that are not ancestors to be updated]' \
'(:)--repo=[default repository to use]:repository:__git_any_repositories' \
'(-u --set-upstream)'{-u,--set-upstream}'[add upstream reference for each branch that is up to date or pushed]' \

View file

@ -360,7 +360,7 @@ case "$words[2]" in
'*:picture file:_imagemagick' && return
if [[ "$state" = profile ]]; then
if compset -P '*:'; then
if compset -P 1 '*:'; then
_files
else
_wanted prefixes expl 'profile type' compadd icc: iptc:

View file

@ -116,7 +116,7 @@ _mkisofs_sparc_boot_images () {
_mkisofs_pathspec () {
local sep
if (( $words[(I)-graft-points] )); then
if ! compset -P '*[^\\]\='; then
if ! compset -P 1 '*[^\\]\='; then
sep='-qS='
fi
fi
@ -335,7 +335,7 @@ else
case "$state" in
(devimg)
if compset -P \*=; then
if compset -P 1 '*='; then
_files
else
_files -g "*(%,@)"

View file

@ -32,7 +32,7 @@ else
fi
;;
sname)
if compset -P '*='; then
if compset -P 1 '*='; then
case "$IPREFIX" in
*DEVICE\=)
_wanted devices expl 'ghostscript device' \

View file

@ -31,7 +31,7 @@ case $state in
state=''
;;
schemata)
if compset -P '*:'; then
if compset -P 1 '*:'; then
_directories && ret=0
else
_wanted schemata expl 'schema' compadd -M 'r:|.=* r:|=*' \

View file

@ -32,7 +32,7 @@ case $state in
sign='sign:sign:((-\:"print all but the last specified bytes/lines"'
sign+=' +\:"print the first specified bytes/lines (default)"))'
digit='digits:digit:(0 1 2 3 4 5 6 7 8 9)'
if compset -P '*[0-9]'; then
if compset -P '[0-9]##'; then
_alternative $mlt $digit && ret=0
elif [[ -z $PREFIX ]]; then
_alternative $sign $digit && ret=0

View file

@ -364,7 +364,7 @@ case "$service" in
'*:picture file:_imagemagick' && return
if [[ "$state" = profile ]]; then
if compset -P '*:'; then
if compset -P 1 '*:'; then
_files
else
_wanted prefixes expl 'profile type' compadd icc: iptc:

View file

@ -578,7 +578,7 @@ encoding)
;;
property)
if compset -P '*='; then
if compset -P 1 '*='; then
_default && return
else
_message -e property-names 'property name'

View file

@ -44,7 +44,7 @@ _lp_job_options()
# The program specified by the style list-printer-options should list jobs in
# the same style as lpoptions -l.
if compset -P '*='; then
if compset -P 1 '*='; then
# List values for the option
case ${IPREFIX%=} in
(media)

View file

@ -69,8 +69,9 @@ case "$state" in
"F $sep Append a \`*' for executable files"
"G $sep Inhibit display of group information"
"Q $sep Enclose file names in double quotes" )
# The "Z" on the next line is sentinel to prevent the character class from being empty.
disp=( ${disp[@]:#[Z$PREFIX]*} )
compset -P '[FGQ]*'
compset -P '[FGQ]#'
compadd -d disp - ${disp[@]%% *} && ret=0
;;
esac

View file

@ -856,7 +856,7 @@ fsopt)
devordir)
local dev_tmp mp_tmp mline
if compset -P '*:'; then
if compset -P 1 '*:'; then
_wanted exports expl 'exported path' compadd \
${${(f)"$(path+=( {/usr,}/sbin(N) ) _call_program exports \
showmount -e ${IPREFIX%:} 2>/dev/null)"}[2,-1]%% *} && ret=0

View file

@ -56,7 +56,7 @@ _perl_normal() {
_perl_m_opt () {
compset -P '-'
if compset -P '*='; then
if compset -P 1 '*='; then
_message -e module-arguments 'module arguments, comma separated'
else
_perl_modules -S= -q

View file

@ -50,7 +50,7 @@ case $state in
local -a directives suf
local code='foreach (ini_get_all() as $k => $v) { echo "$k\n"; }'
directives=( $(_call_program directives $words[1] -r ${(q)code} 2>/dev/null) )
if compset -P '*='; then
if compset -P 1 '*='; then
_default && return 0
else
compset -S '=*' || suf=( -qS '=' )

View file

@ -38,9 +38,9 @@ _rlogin () {
'*:files:->files' && ret=0
if [[ -n "$state" ]]; then
if compset -P '*:'; then
if compset -P 1 '*:'; then
_remote_files -- rsh && ret=0
elif compset -P '*@'; then
elif compset -P 1 '*@'; then
_wanted hosts expl host _rlogin_hosts -S: && ret=0
else
_alternative \

View file

@ -200,7 +200,7 @@ _ssh () {
case "$lstate" in
option)
if compset -P '*='; then
if compset -P 1 '*='; then
case "${IPREFIX#-o}" in
(#i)(ciphers|macs|kexalgorithms|hostkeyalgorithms|pubkeyacceptedkeytypes|hostbasedkeytypes)=)
if ! compset -P +; then
@ -628,9 +628,9 @@ _ssh () {
fi
;;
file)
if compset -P '[^./][^/]#:'; then
if compset -P 1 '[^./][^/]#:'; then
_remote_files -- ssh ${(kv)~opt_args[(I)-[FP1246]]/-P/-p} && ret=0
elif compset -P '*@'; then
elif compset -P 1 '*@'; then
suf=( -S '' )
compset -S ':*' || suf=( -r: -S: )
_wanted hosts expl 'remote host name' _ssh_hosts $suf && ret=0
@ -642,9 +642,9 @@ _ssh () {
fi
;;
rfile)
if compset -P '*:'; then
if compset -P 1 '*:'; then
_remote_files -- ssh && ret=0
elif compset -P '*@'; then
elif compset -P 1 '*@'; then
_wanted hosts expl host _ssh_hosts -r: -S: && ret=0
else
_alternative \

View file

@ -56,7 +56,7 @@ case $state in
sign='signs:sign:((+\:"start at the specified byte/line"'
sign+=' -\:"output the last specified bytes/lines (default)"))'
digit='digits:digit:(0 1 2 3 4 5 6 7 8 9)'
if compset -P '*[0-9]'; then
if compset -P '[0-9]##'; then
_alternative $mlt $digit && ret=0
elif [[ -z $PREFIX ]]; then
_alternative $sign $digit && ret=0

View file

@ -90,7 +90,7 @@ case "$state" in
option)
local -a options
options=( ${${(M)${(f)"$(_call_program options $words[1] -show-option 2>/dev/null)"}:# -o *}/(#b) -o (*)=[^ ]#[[:blank:]]##(*)/$match[1]:${match[2]:l}} )
if compset -P '*='; then
if compset -P 1 '*='; then
_message -e values 'value'
else
compset -S '=*' || suf=( -S '=' )
@ -98,7 +98,7 @@ case "$state" in
fi
;;
pauth)
if compset -P '*:'; then
if compset -P 1 '*:'; then
_message -e passwords 'password'
else
compset -S ':*' || suf=( -S ':' )

View file

@ -89,9 +89,8 @@ case $state in
;;
redirection)
redir="${PREFIX%%:*}"
if compset -P '*='; then
if compset -P 1 '*='; then
curcontext="${curcontext%:*}:$redir"
compset -P '*='
case $redir in
comport|lptport) _wanted devices expl device _files -g '*(-%)' && ret=0 ;;
disk) _directories && ret=0 ;;

View file

@ -82,12 +82,16 @@ xev)
xhost)
local type tmp match
if [[ -z $PREFIX ]]; then
_describe prefixes '(-:disallow +:allow)' -S '' -r ''
fi
if compset -P '-'; then
tmp=(${(f)"$(xhost)"})
shift tmp
tmp=(${tmp:#LOCAL:|<*>})
if [[ "$tmp" = *:* ]]; then
if compset -P '(#b)(*):'; then
if compset -P 1 '(#b)(*):'; then
type="$match[1]"
_tags displays
while _tags; do
@ -118,7 +122,7 @@ xhost)
if [[ "$PREFIX" = *:* ]]; then
type="${(L)PREFIX%%:*}"
compset -P '*:'
compset -P 1 '*:'
case "$type" in
inet) _hosts && ret=0;;

View file

@ -68,7 +68,7 @@ esac
if [[ -n $state ]]; then
zstyle -s ":completion:${curcontext}:" list-separator sep || sep=--
if [[ -z ${line:#*=*} ]] && compset -P '*='; then
if [[ -z ${line:#*=*} ]] && compset -P 1 '*='; then
_message -e replacements 'replacement'
elif [[ -prefix [0-9] ]]; then
events=( ${(0)"$(printf "%-${#HISTNO}.${#HISTNO}s $sep %s\0" "${(kv)history[@]}")"} )

View file

@ -2,4 +2,4 @@
local expl
_wanted arrays expl array _parameters "$@" - -g '*array*'
_wanted arrays expl array _parameters "$@" -g '*array*'

View file

@ -1,5 +1,8 @@
#autoload
# Complete 'globbing flags', i.e., '(#x)'; everything up to the '#' will
# have been "compset -P"'d by the caller.
local ret=1
local -a flags

View file

@ -58,11 +58,14 @@ if compset -P '%[FK]'; then
fi
if compset -P '%[0-9-\\]#(\\|)\([0-9-]#[^0-9]'; then
# ternary conditional: first delimiter
compset -S '*'
_delimiters && ret=0
elif compset -P '%[0-9-\\]#[<>\]]'; then
# truncation
_message -e replacements 'replacement string'
elif compset -P '%[0-9-\\]#(\\|)\([0-9-]#'; then
# ternary conditional: condition character
compset -S '[.:+/-%]*' || suf=( -S . )
compset -S '*'
specs=(

View file

@ -1,7 +1,7 @@
#compdef getopts unset
# This will handle completion of keys of associative arrays, e.g. at
# `vared foo[<TAB>'.
# `vared foo[<TAB>' could complete to `vared foo[key]'.
local ret=1