1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-10-23 04:30:24 +02:00

_wanted now tests both tags and labels; change places where _wanted was called without a command; allow multiple patterns per string in file-patterns; update _next_tags to work with labels (10632)

This commit is contained in:
Sven Wischnowsky 2000-04-11 07:57:56 +00:00
parent 37012f06a7
commit fac3086d97
57 changed files with 1320 additions and 1097 deletions

View file

@ -1,3 +1,36 @@
2000-04-11 Sven Wischnowsky <wischnow@informatik.hu-berlin.de>
* 10632: Completion/Base/_brace_parameter, Completion/Base/_condition,
Completion/Base/_default, Completion/Base/_describe,
Completion/Base/_first, Completion/Base/_jobs,
Completion/Base/_values, Completion/Builtins/_compdef,
Completion/Builtins/_hash, Completion/Builtins/_pids,
Completion/Builtins/_popd, Completion/Builtins/_sched,
Completion/Builtins/_signals, Completion/Builtins/_vars,
Completion/Builtins/_zcompile, Completion/Builtins/_zftp,
Completion/Builtins/_zpty, Completion/Builtins/_zstyle,
Completion/Commands/_next_tags, Completion/Core/_all_labels,
Completion/Core/_files, Completion/Core/_next_label,
Completion/Core/_requested, Completion/Core/_wanted,
Completion/Debian/_apt, Completion/Debian/_deb_packages,
Completion/User/_cvs, Completion/User/_gdb,
Completion/User/_gprof, Completion/User/_groups,
Completion/User/_lp, Completion/User/_mh, Completion/User/_mount,
Completion/User/_netscape, Completion/User/_nslookup,
Completion/User/_rlogin, Completion/User/_socket,
Completion/User/_tiff, Completion/User/_urls,
Completion/User/_users, Completion/User/_users_on,
Completion/User/_whois, Completion/X/_x_colormapid,
Completion/X/_x_display, Completion/X/_x_extension,
Completion/X/_x_font, Completion/X/_x_keysym,
Completion/X/_x_window, Completion/X/_xmodmap,
Completion/X/_xutils, Completion/X/_xwit, Doc/Zsh/compsys.yo,
Etc/completion-style-guide, Functions/Zftp/zfcd_match,
Functions/Zftp/zfget_match, Src/Zle/computil.c: _wanted now tests
both tags and labels; change places where _wanted was called
without a command; allow multiple patterns per string in
file-patterns; update _next_tags to work with labels
2000-04-10 Bart Schaefer <schaefer@brasslantern.com> 2000-04-10 Bart Schaefer <schaefer@brasslantern.com>
* 10628: Doc/Zsh/compsys.yo, Completion/User/_make: Check for * 10628: Doc/Zsh/compsys.yo, Completion/User/_make: Check for

View file

@ -1,5 +1,3 @@
#defcomp -brace-parameter- #compdef -brace-parameter-
# Simple but without spiffy suffix handling: compgen -v -S '} ' _parameters -e
compadd -S '} ' -r '-:?#%+=[/' - "${(@)${${${(f)$(typeset)}%%\=*}##* }:gs/'//}"

View file

@ -1,10 +1,55 @@
#defcomp -condition- #compdef -condition-
if [[ -current -1 -o ]]; then local prev="$words[CURRENT-1]" ret=1
complist -o -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}'
elif [[ -current -1 -nt || -current -1 -ot || -current -1 -ef ]]; then if [[ "$prev" = -o ]]; then
_files _tags -C -o options && _options
elif [[ "$prev" = -([a-hkprsuwxLOGSN]|[no]t|ef) ]]; then
_tags -C "$prev" files && _files
else else
_files if [[ "$PREFIX" = -* ]] ||
complist -v ! zstyle -T ":completion:${curcontext}:options" prefix-needed; then
if [[ "$prev" = (\[\[|\|\||\&\&|\!|\() ]]; then
_describe -o 'condition code' \
'( -a:existing\ file
-b:block\ special\ file
-c:character\ special\ file
-d:directory
-e:existing\ file
-f:regular\ file
-g:setgid\ bit
-h:symbolic\ link
-k:sticky\ bit
-n:non-empty\ string
-o:option
-p:named\ pipe
-r:readable\ file
-s:non-empty\ file
-t:terminal\ file\ descriptor
-u:setuid\ bit
-w:writable\ file
-x:executable\ file
-z:empty\ string
-L:symbolic\ link
-O:own\ file
-G:group-owned\ file
-S:socket
-N:unread\ file)' && ret=0
else
_describe -o 'condition code' \
'( -nt:newer\ than
-ot:older\ than
-ef:same\ file
-eq:numerically\ equal
-ne:numerically\ not\ equal
-lt:numerically\ less\ than
-le:numerically\ less\ then\ or\ equal
-lt:numerically\ greater\ than
-le:numerically\ greater\ then\ or\ equal)' && ret=0
fi
fi
_alternative 'files:: _files' 'parameters:: _parameters' && ret=0
return ret
fi fi

View file

@ -12,8 +12,6 @@ if { zstyle -s ":completion:${curcontext}:" use-compctl ctl ||
compcall "$opt[@]" || return 0 compcall "$opt[@]" || return 0
fi fi
_wanted files || return 1
_files && return 0 _files && return 0
# magicequalsubst allows arguments like <any-old-stuff>=~/foo to do # magicequalsubst allows arguments like <any-old-stuff>=~/foo to do

View file

@ -14,8 +14,6 @@ fi
# Do the tests. `showd' is set if the descriptions should be shown. # Do the tests. `showd' is set if the descriptions should be shown.
_wanted "$_type" || return 1
zstyle -T ":completion:${curcontext}:$_type" verbose && _showd=yes zstyle -T ":completion:${curcontext}:$_type" verbose && _showd=yes
_descr="$1" _descr="$1"
@ -24,30 +22,35 @@ shift
[[ "$_type" = options ]] && [[ "$_type" = options ]] &&
zstyle -t ":completion:${curcontext}:options" prefix-hidden && _hide=yes zstyle -t ":completion:${curcontext}:options" prefix-hidden && _hide=yes
while _next_label "$_type" _expl "$_descr"; do _tags "$_type"
while _tags; do
while _next_label "$_type" _expl "$_descr"; do
if [[ -n "$_showd" ]]; then if [[ -n "$_showd" ]]; then
compdescribe -I ' -- ' "$@" compdescribe -I ' -- ' "$@"
else else
compdescribe -i "$@" compdescribe -i "$@"
fi
while compdescribe -g _args _tmpd _tmpmd _tmps _tmpms; do
# See if we should remove the option prefix characters.
if [[ -n "$_hide" ]]; then
if [[ "$PREFIX" = --* ]]; then
_tmpd=( "${(@)_tmpd#--}" )
_tmps=( "${(@)_tmps#--}" )
elif [[ "$PREFIX" = [-+]* ]]; then
_tmpd=( "${(@)_tmpd#[-+]}" )
_tmps=( "${(@)_tmps#[-+]}" )
fi
fi fi
compadd "$_args[@]" "$_expl[@]" -ld _tmpd - "$_tmpmd[@]" && _ret=0 while compdescribe -g _args _tmpd _tmpmd _tmps _tmpms; do
compadd "$_args[@]" "$_expl[@]" -d _tmps - "$_tmpms[@]" && _ret=0
# See if we should remove the option prefix characters.
if [[ -n "$_hide" ]]; then
if [[ "$PREFIX" = --* ]]; then
_tmpd=( "${(@)_tmpd#--}" )
_tmps=( "${(@)_tmps#--}" )
elif [[ "$PREFIX" = [-+]* ]]; then
_tmpd=( "${(@)_tmpd#[-+]}" )
_tmps=( "${(@)_tmps#[-+]}" )
fi
fi
compadd "$_args[@]" "$_expl[@]" -ld _tmpd - "$_tmpmd[@]" && _ret=0
compadd "$_args[@]" "$_expl[@]" -d _tmps - "$_tmpms[@]" && _ret=0
done
done done
(( _ret )) || return 0
done done
return _ret
return 1

View file

@ -35,28 +35,35 @@
# and hitting TAB. # and hitting TAB.
# #
# if [[ "$PREFIX" = *,, ]]; then # if [[ "$PREFIX" = *,, ]]; then
# local max i=1 # local max i=1 expl opt
# #
# PREFIX="$PREFIX[1,-2]" # PREFIX="$PREFIX[1,-2]"
# # If a numeric prefix is given, we use it as the number of # # If a numeric prefix is given, we use it as the number of
# # lines (multiplied by ten below) in the history to search. # # lines (multiplied by ten below) in the history to search.
# if [[ NUMERIC -gt 1 ]]; then # if [[ ${NUMERIC:-1} -gt 1 ]]; then
# max=$NUMERIC # max=$NUMERIC
# NUMERIC=1 # unset NUMERIC
# else # else
# # The default is to search the last 100 lines. # # The default is to search the last 100 lines.
# max=10 # max=10
# fi # fi
# # We first search in the last ten lines, then in the last # # We first search in the last ten words, then in the last
# # twenty lines, and so on... # # twenty words, and so on...
# while [[ i -le max ]]; do # while [[ i -le max ]]; do
# if compgen -X "%Bhistory ($n):%b" -Q -H $(( i*10 )) ''; then # if zstyle -t ":completion:${curcontext}:history-words" sort; then
# opt=-J
# else
# opt=-V
# fi
# if _wanted "$opt" history-words expl "history ($n)" \
# compadd "$expl[@]" -Q - \
# "${(@)${(@)historywords:#[\$'\"]*}[1,i*10]}"; then
# # We have found at least one matching word, so we switch # # We have found at least one matching word, so we switch
# # on menu-completion and make sure that no other # # on menu-completion and make sure that no other
# # completion function is called by setting _comp_skip. # # completion function is called by setting _compskip.
# compstate[insert]=menu # compstate[insert]=menu
# _comp_skip=1 # _compskip=all
# return # return 0
# fi # fi
# (( i++ )) # (( i++ ))
# done # done

View file

@ -2,8 +2,6 @@
local expl disp jobs job jids pfx='%' desc how expls local expl disp jobs job jids pfx='%' desc how expls
_wanted jobs || return 1
if [[ "$1" = -t ]]; then if [[ "$1" = -t ]]; then
zstyle -T ":completion:${curcontext}:jobs" prefix-needed && zstyle -T ":completion:${curcontext}:jobs" prefix-needed &&
[[ "$PREFIX" != %* && compstate[nmatches] -ne 0 ]] && return 1 [[ "$PREFIX" != %* && compstate[nmatches] -ne 0 ]] && return 1
@ -79,7 +77,7 @@ else
fi fi
if [[ -n "$desc" ]]; then if [[ -n "$desc" ]]; then
_all_labels jobs expl "$expls" compadd "$@" -ld disp - "%$^jobs[@]" _wanted jobs expl "$expls" compadd "$@" -ld disp - "%$^jobs[@]"
else else
_all_labels jobs expl "$expls" compadd "$@" - "%$^jobs[@]" _wanted jobs expl "$expls" compadd "$@" - "%$^jobs[@]"
fi fi

View file

@ -18,7 +18,7 @@ if compvalues -i "$@"; then
if ! compvalues -D descr action; then if ! compvalues -D descr action; then
_wanted values || return 1 _tags values || return 1
curcontext="${oldcontext%:*}:values" curcontext="${oldcontext%:*}:values"

View file

@ -19,15 +19,13 @@ case $state in
_wanted commands expl 'completed command' compadd - ${(k)_comps} _wanted commands expl 'completed command' compadd - ${(k)_comps}
;; ;;
cfun) cfun)
if _wanted functions; then list=( ${^fpath:/.}/_(|*[^~])(N:t) )
list=( ${^fpath:/.}/_(|*[^~])(N:t) ) if zstyle -T ":completion:${curcontext}:functions" prefix-hidden; then
if zstyle -T ":completion:${curcontext}:functions" prefix-hidden; then disp=( ${list[@]#_} )
disp=( ${list[@]#_} ) _wanted functions expl 'completion function' \
_all_labels functions expl 'completion function' \ compadd -d disp - "$list[@]"
compadd -d disp - "$list[@]" else
else _wanted functions expl 'completion function' compadd - "$list[@]"
_all_labels functions expl 'completion function' compadd - "$list[@]"
fi
fi fi
;; ;;
style) style)

View file

@ -1,13 +1,16 @@
#defcomp hash #compdef hash
if [[ -mword 1 -*d* ]]; then local expl
if [[ -string 1 '=' ]]; then
_path_files -g '*(-/)' if [[ "$words[2]" = -*d* ]]; then
if compset -P 1 '*='; then
_wanted -C -d-value files expl directories _path_files -/
else else
complist -n -q -S '=' _wanted -C -d named-directories expl 'named directory' \
compadd -q -S '=' - "${(@k)nameddirs}"
fi fi
elif [[ -string 1 '=' ]]; then elif compset -P 1 '*='; then
_files -/g '*(*)' _wanted -C value values expl 'executable file' _files "$expl[@]" -g '*(-*)'
else else
complist -m -q -S '=' _wanted -C name commands expl command compadd -q -S '=' - "${(@k)commands}"
fi fi

View file

@ -5,7 +5,7 @@
local out list expl match desc listargs args local out list expl match desc listargs args
_wanted processes || return 1 _tags processes || return 1
if [[ "$1" = -m ]]; then if [[ "$1" = -m ]]; then
match="${2}*" match="${2}*"
@ -29,6 +29,6 @@ else
desc=() desc=()
fi fi
_all_labels processes expl 'process ID' \ _wanted processes expl 'process ID' \
compadd "$@" "$desc[@]" - \ compadd "$@" "$desc[@]" - \
${${${(M)${(f)"${out}"}[2,-1]:#[ ]#${PREFIX}[0-9]#${SUFFIX}[ ]#*${~match}}## #}%% *} ${${${(M)${(f)"${out}"}[2,-1]:#[ ]#${PREFIX}[0-9]#${SUFFIX}[ ]#*${~match}}## #}%% *}

View file

@ -12,8 +12,6 @@ local expl list lines revlines disp
! zstyle -T ":completion:${curcontext}:directory-stack" prefix-needed || ! zstyle -T ":completion:${curcontext}:directory-stack" prefix-needed ||
[[ $PREFIX = [-+]* ]] || return 1 [[ $PREFIX = [-+]* ]] || return 1
_wanted directory-stack || return 1
if zstyle -T ":completion:${curcontext}:directory-stack" verbose; then if zstyle -T ":completion:${curcontext}:directory-stack" verbose; then
# get the list of directories with their canonical number # get the list of directories with their canonical number
# and turn the lines into an array, removing the current directory # and turn the lines into an array, removing the current directory
@ -39,5 +37,5 @@ else
disp=() disp=()
fi fi
_all_labels -V directory-stack expl 'directory stack' \ _wanted -V directory-stack expl 'directory stack' \
compadd "$@" "$disp[@]" -Q - "$list[@]" compadd "$@" "$disp[@]" -Q - "$list[@]"

View file

@ -4,15 +4,13 @@ local expl lines disp
if [[ CURRENT -eq 2 ]]; then if [[ CURRENT -eq 2 ]]; then
if compset -P -; then if compset -P -; then
_wanted -C - jobs || return 1
lines=(${(f)"$(sched)"}) lines=(${(f)"$(sched)"})
if zstyle -T ":completion:${curcontext}:jobs" verbose; then if zstyle -T ":completion:${curcontext}:jobs" verbose; then
disp=( -ld lines ) disp=( -ld lines )
else else
disp=() disp=()
fi fi
[[ -z $lines ]] || _all_labels jobs expl 'scheduled jobs' \ [[ -z $lines ]] || _wanted jobs expl 'scheduled jobs' \
compadd "$disp[@]" - {1..$#lines} compadd "$disp[@]" - {1..$#lines}
return return
else else

View file

@ -20,10 +20,9 @@ done
[[ "$1" = -(|-) ]] && shift [[ "$1" = -(|-) ]] && shift
if _wanted signals && if [[ -z "$minus" ]] ||
{ [[ -z "$minus" ]] || ! zstyle -T ":completion:${curcontext}:signals" prefix-needed ||
! zstyle -T ":completion:${curcontext}:signals" prefix-needed || [[ "$PREFIX" = -* ]]; then
[[ "$PREFIX" = -* ]] } ; then
local disp tmp local disp tmp
if zstyle -t ":completion:${curcontext}:signals" prefix-hidden; then if zstyle -t ":completion:${curcontext}:signals" prefix-hidden; then
@ -32,7 +31,7 @@ if _wanted signals &&
else else
disp=() disp=()
fi fi
_all_labels signals expl signal \ _wanted signals expl signal \
compadd "$@" "$disp[@]" -M 'm:{a-z}={A-Z}' - \ compadd "$@" "$disp[@]" -M 'm:{a-z}={A-Z}' - \
"${minus}${(@)^signals[1,last]}" "${minus}${(@)^signals[1,last]}"
fi fi

View file

@ -1,8 +1,8 @@
#compdef getopts read unset vared #compdef getopts read unset vared
# This will handle completion of keys of associative arrays, e.g. at # This will handle completion of keys of associative arrays, e.g. at
# `vared compconfig[<TAB>'. However, in this version the [ must be # `vared foo[<TAB>'. However, in this version the [ must be added
# added by hand. # by hand.
if [[ $PREFIX = *\[* ]]; then if [[ $PREFIX = *\[* ]]; then
local var=${PREFIX%%\[*} local var=${PREFIX%%\[*}
@ -16,13 +16,9 @@ if [[ $PREFIX = *\[* ]]; then
if [[ ${(tP)var} = assoc* ]]; then if [[ ${(tP)var} = assoc* ]]; then
local expl local expl
_tags subscript association-keys || return 1 _wanted -C subscript association-keys expl 'association key' \
compadd $addclose - ${(kP)var}
_description expl 'association key'
compadd "$expl[@]" $addclose - ${(kP)var}
fi fi
else else
_tags any parameters || return 1
_parameters _parameters
fi fi

View file

@ -18,5 +18,6 @@ _arguments -s \
if (( $+opt_args[-c] )); then if (( $+opt_args[-c] )); then
_wanted functions expl 'function to write' compadd - ${(k)functions} _wanted functions expl 'function to write' compadd - ${(k)functions}
else else
_wanted file expl 'zsh source file' _files _description files expl 'zsh source file'
_files "$expl[@]"
fi fi

View file

@ -28,35 +28,34 @@ fi
case $subcom in case $subcom in
*(cd|ls|dir)) *(cd|ls|dir))
# complete remote directories # complete remote directories
_wanted directories && zfcd_match $PREFIX $SUFFIX _tags directories && zfcd_match $PREFIX $SUFFIX
;; ;;
*(get(|at)|gcp|delete|remote)) *(get(|at)|gcp|delete|remote))
# complete remote files # complete remote files
_wanted files && zfget_match $PREFIX $SUFFIX _tags files && zfget_match $PREFIX $SUFFIX
;; ;;
*(put(|at)|pcp)) *(put(|at)|pcp))
# complete local files # complete local files
_wanted files && _files _files
;; ;;
*(open|anon|params)) *(open|anon|params))
# complete hosts: should do cleverer stuff with user names # complete hosts: should do cleverer stuff with user names
_wanted hosts && _hosts _hosts
;; ;;
*(goto|mark)) *(goto|mark))
# complete bookmarks. First decide if ncftp mode is go. # complete bookmarks. First decide if ncftp mode is go.
_wanted bookmarks || return 1
if [[ $words[2] = -*n* ]]; then if [[ $words[2] = -*n* ]]; then
if [[ -f ~/.ncftp/bookmarks ]]; then if [[ -f ~/.ncftp/bookmarks ]]; then
_all_labels bookmarks expl bookmark \ _wanted bookmarks expl bookmark \
compadd - $(awk -F, 'NR > 2 { print $1 }' ~/.ncftp/bookmarks) compadd - $(awk -F, 'NR > 2 { print $1 }' ~/.ncftp/bookmarks)
fi fi
else else
if [[ -f ${ZFTP_BMFILE:=${ZDOTDIR:-$HOME}/.zfbkmarks} ]]; then if [[ -f ${ZFTP_BMFILE:=${ZDOTDIR:-$HOME}/.zfbkmarks} ]]; then
_all_labels bookmarks expl bookmark \ _wanted bookmarks expl bookmark \
compadd - $(awk '{print $1}' $ZFTP_BMFILE) compadd - $(awk '{print $1}' $ZFTP_BMFILE)
fi fi
fi fi
@ -72,7 +71,7 @@ case $subcom in
# complete arguments like sess1:file1 sess2:file2 # complete arguments like sess1:file1 sess2:file2
if [[ $PREFIX = *:* ]]; then if [[ $PREFIX = *:* ]]; then
# complete file in the given session # complete file in the given session
_wanted files || return 1 _tags files || return 1
local sess=${PREFIX%%:*} oldsess=$ZFTP_SESSION local sess=${PREFIX%%:*} oldsess=$ZFTP_SESSION
compset -p $(( $#sess + 1 )) compset -p $(( $#sess + 1 ))
[[ -n $sess ]] && zftp session $sess [[ -n $sess ]] && zftp session $sess

View file

@ -11,13 +11,13 @@ _arguments -C -s \
'(-e -b -d -w -r)-L[list defined commands as calls]' \ '(-e -b -d -w -r)-L[list defined commands as calls]' \
'(-r)*::args:_normal' '(-r)*::args:_normal'
if [[ $state = name ]] && _wanted names; then if [[ $state = name ]]; then
list=( ${${(f)"$(zpty)"}#*\) } ) list=( ${${(f)"$(zpty)"}#*\) } )
names=( ${list%%:*} ) names=( ${list%%:*} )
if zstyle -T ":completion:${curcontext}" verbose; then if zstyle -T ":completion:${curcontext}" verbose; then
zformat -a list ' --' ${${(f)"$(zpty)"}#*\) } zformat -a list ' --' ${${(f)"$(zpty)"}#*\) }
_all_labels names expl 'zpty command names' compadd -d list - "$names[@]" _wanted names expl 'zpty command names' compadd -d list - "$names[@]"
else else
_all_labels names expl 'zpty command names' compadd - "$names[@]" _wanted names expl 'zpty command names' compadd - "$names[@]"
fi fi
fi fi

View file

@ -96,20 +96,18 @@ while [[ -n $state ]]; do
case "$ostate" in case "$ostate" in
contexts) contexts)
if _wanted contexts; then if [[ $PREFIX != :*: ]]; then
if [[ $PREFIX != :*: ]]; then _wanted contexts expl context compadd -P : -S : completion zftp
_all_labels contexts expl context compadd -P : -S : completion zftp elif [[ $PREFIX = :completion:* ]] && _tags contexts; then
elif [[ $PREFIX = :completion:* ]]; then mesg=''
mesg='' case "$PREFIX" in
case "$PREFIX" in :completion:[^:]#) mesg=function ;;
:completion:[^:]#) mesg=function ;; :completion:[^:]#:[^:]#) mesg=completer ;;
:completion:[^:]#:[^:]#) mesg=completer ;; :completion:[^:]#:[^:]#:[^:]#) mesg='command or context' ;;
:completion:[^:]#:[^:]#:[^:]#) mesg='command or context' ;; :completion:[^:]#:[^:]#:[^:]#:[^:]#) mesg=argument ;;
:completion:[^:]#:[^:]#:[^:]#:[^:]#) mesg=argument ;; :completion:[^:]#:[^:]#:[^:]#:[^:]#:[^:]#) mesg=tag ;;
:completion:[^:]#:[^:]#:[^:]#:[^:]#:[^:]#) mesg=tag ;; esac
esac [[ -n "$mesg" ]] && _message "$mesg"
[[ -n "$mesg" ]] && _message "$mesg"
fi
fi fi
;; ;;

View file

@ -3,30 +3,103 @@
# Main widget. # Main widget.
_next_tags() { _next_tags() {
local comp ins local ins ops="$PREFIX$SUFFIX"
if [[ -z $compstate[old_list] ]]; then unfunction _all_labels _next_label
comp=()
_all_labels() {
local gopt=-J len tmp pre suf ret=1 descr spec
if [[ "$1" = -([12]|)[VJ] ]]; then
gopt="$1"
shift
fi
tmp=${argv[(ib:4:)-]}
len=$#
if [[ tmp -lt len ]]; then
pre=$(( tmp-1 ))
suf=$tmp
elif [[ tmp -eq $# ]]; then
pre=-2
suf=$(( len+1 ))
else
pre=4
suf=5
fi
while comptags -A "$1" curtag spec; do
[[ "$_next_tags_not" = *\ ${spec}\ * ]] && continue
_comp_tags="$_comp_tags $spec "
if [[ "$curtag" = *:* ]]; then
zformat -f descr "${curtag#*:}" "d:$3"
_description "$gopt" "${curtag%:*}" "$2" "$descr"
curtag="${curtag%:*}"
"$4" "${(P@)2}" "${(@)argv[5,-1]}"
else
_description "$gopt" "$curtag" "$2" "$3"
"${(@)argv[4,pre]}" "${(P@)2}" "${(@)argv[suf,-1]}" && ret=0
fi
done
return ret
}
_next_label() {
local gopt=-J descr spec
if [[ "$1" = -([12]|)[VJ] ]]; then
gopt="$1"
shift
fi
if comptags -A "$1" curtag spec; then
[[ "$_next_tags_not" = *\ ${spec}\ * ]] && continue
_comp_tags="$_comp_tags $spec "
if [[ "$curtag" = *:* ]]; then
zformat -f descr "${curtag#*:}" "d:$3"
_description "$gopt" "${curtag%:*}" "$2" "$descr"
curtag="${curtag%:*}"
eval "${2}=( \${(P)2} \$argv[4,-1] )"
else
_description "$gopt" "$curtag" "$2" "$3"
eval "${2}=( \$argv[4,-1] \${(P)2} )"
fi
return 0
fi
return 1
}
if [[ "${LBUFFER%${PREFIX}}" = "$_next_tags_pre" ]]; then
PREFIX="$_next_tags_pfx"
SUFFIX="$_next_tags_sfx"
else else
comp=(_complete) _next_tags_pre="${LBUFFER%${PREFIX}}"
if [[ "$LASTWIDGET" = (_next_tags|list-*|*complete*) ]]; then
PREFIX="$_lastcomp[prefix]"
SUFFIX="$_lastcomp[suffix]"
fi
fi fi
(( $+_sort_tags )) || _next_tags_not=
_sort_tags=_next_tags_sort
_next_tags_pre="${LBUFFER%${PREFIX}}"
_next_tags_not="$_next_tags_not $_lastcomp[tags]" _next_tags_not="$_next_tags_not $_lastcomp[tags]"
_next_tags_pfx="$PREFIX"
_next_tags_sfx="$SUFFIX"
if [[ -n "$compstate[old_insert]" ]]; then if [[ -n "$compstate[old_insert]" ]]; then
PREFIX="$_lastcomp[prefix]"
SUFFIX="$_lastcomp[suffix]"
ins=1 ins=1
else
ins=unambiguous
fi fi
_main_complete "$comp[@]" _main_complete _complete _next_tags_completer
[[ $compstate[insert] = automenu ]] && [[ $compstate[insert] = automenu ]] && compstate[insert]=automenu-unambiguous
compstate[insert]=automenu-unambiguous [[ $compstate[insert] = *unambiguous && -n "$ops" &&
-z "$_lastcomp[unambiguous]" ]] && compadd -Uns "$SUFFIX" - "$PREFIX"
compstate[insert]="$ins" compstate[insert]="$ins"
compstate[list]='list force' compstate[list]='list force'
@ -34,11 +107,19 @@ _next_tags() {
compprefuncs=( "$compprefuncs[@]" _next_tags_pre ) compprefuncs=( "$compprefuncs[@]" _next_tags_pre )
} }
# Completer, for wrap-around.
_next_tags_completer() {
_next_tags_not=
_complete
}
# Pre-completion function. # Pre-completion function.
_next_tags_pre() { _next_tags_pre() {
# Probably `remove' our sort function. A better test would be nice, but # Probably `remove' our label functions. A better test would be nice, but
# I think one should still be able to edit the current word between # I think one should still be able to edit the current word between
# attempts to complete it. # attempts to complete it.
@ -47,65 +128,10 @@ _next_tags_pre() {
compstate[insert]=menu:2 compstate[insert]=menu:2
return 0 return 0
elif [[ ${LBUFFER%${PREFIX}} != ${_next_tags_pre}* ]]; then elif [[ ${LBUFFER%${PREFIX}} != ${_next_tags_pre}* ]]; then
unset _sort_tags unfunction _all_labels _next_label
autoload -U _all_labels _next_label
else else
compprefuncs=( "$compprefuncs[@]" _next_tags_pre ) compprefuncs=( "$compprefuncs[@]" _next_tags_pre )
[[ -n "$compstate[old_list]" && -n "$_next_tags_reset" ]] &&
_next_tags_not= _next_tags_reset=
fi
}
# Helper function for sorting tags. Most of this is copied from _tags.
_next_tags_sort() {
local order tags tag nodef tmp
zstyle -a ":completion:${curcontext}:" tag-order order ||
order=('arguments values' options)
# But we also remove the tags we've already tried...
tags=( "${(@)order:#(${(j:|:)~${=_next_tags_not}})(|:*)}" )
# ... unless that would remove all offered tags.
if [[ $funcstack[4] = _files ]]; then
if zstyle -a ":completion:${curcontext}:" file-patterns tmp; then
[[ "$tags" = *${${tmp[-1]##[^\\]:}%:*}* ]] &&
tags=( $order ) _next_tags_reset=yes
else
[[ "$tags" = *all-files* ]] && tags=( $order ) _next_tags_reset=yes
fi
else
[[ $#tags -ne $#order && "$tags" != *(${(j:|:)~argv})* ]] &&
tags=( $order ) _next_tags_reset=yes
fi
for tag in $tags; do
case $tag in
-) nodef=yes;;
*\(\)) "${${tag%%[ ]#\(\)}##[ ]#}" "$@";;
\!*) comptry "${(@)argv:#(${(j:|:)~${=~tag[2,-1]}})}";;
?*) comptry -m "$tag";;
esac
done
if [[ -z "$nodef" ]]; then
if [[ $funcstack[4] = _files ]]; then
if zstyle -a ":completion:${curcontext}:" file-patterns tmp; then
[[ "$argv" = *${${tmp[-1]#*[^\\]:}%:*}* ]] && _next_tags_reset=yes
else
[[ "$argv" = *all-files* ]] && _next_tags_reset=yes
fi
fi
tmp=( "${(@)argv:#(${(j:|:)~${=_next_tags_not}})(|:*)}" )
# $prev is set in _tags!
if [[ -n "$prev" && ( $#tmp -ne 0 || $funcstack[4] = _files ) ]]; then
comptry "$tmp[@]"
else
comptry "$argv[@]"
fi
fi fi
} }

View file

@ -1,11 +1,7 @@
#autoload #autoload
local gopt=-J len tmp pre suf tloop ret=1 descr local gopt=-J len tmp pre suf ret=1 descr spec
if [[ "$1" = -t ]]; then
tloop=yes
shift
fi
if [[ "$1" = -([12]|)[VJ] ]]; then if [[ "$1" = -([12]|)[VJ] ]]; then
gopt="$1" gopt="$1"
shift shift
@ -24,21 +20,19 @@ else
suf=5 suf=5
fi fi
while [[ -z "$tloop" ]] || comptags -N; do while comptags -A "$1" curtag spec; do
while comptags -A "$1" curtag; do _comp_tags="$_comp_tags $spec "
if [[ "$curtag" = *:* ]]; then if [[ "$curtag" = *:* ]]; then
zformat -f descr "${curtag#*:}" "d:$3" zformat -f descr "${curtag#*:}" "d:$3"
_description "$gopt" "${curtag%:*}" "$2" "$descr" _description "$gopt" "${curtag%:*}" "$2" "$descr"
curtag="${curtag%:*}" curtag="${curtag%:*}"
"$4" "${(P@)2}" "${(@)argv[5,-1]}" "$4" "${(P@)2}" "${(@)argv[5,-1]}"
else else
_description "$gopt" "$curtag" "$2" "$3" _description "$gopt" "$curtag" "$2" "$3"
"${(@)argv[4,pre]}" "${(P@)2}" "${(@)argv[suf,-1]}" && ret=0 "${(@)argv[4,pre]}" "${(P@)2}" "${(@)argv[suf,-1]}" && ret=0
fi fi
done
[[ -z "$tloop" || ret -eq 0 ]] && break
done done
return ret return ret

View file

@ -6,7 +6,7 @@ zparseopts -a opts \
'/=tmp' 'f=tmp' 'g+:-=tmp' q n 1 2 P: S: r: R: W: X+: M+: F: J+: V+: '/=tmp' 'f=tmp' 'g+:-=tmp' q n 1 2 P: S: r: R: W: X+: M+: F: J+: V+:
type="${(@j::M)${(@)tmp#-}#?}" type="${(@j::M)${(@)tmp#-}#?}"
(( $tmp[(I)-g*] )) && glob="${(j: :)${(@M)tmp:#-g*}#-g}" (( $tmp[(I)-g*] )) && glob="${(j:,:)${(@M)tmp:#-g*}#-g}"
ign=$opts[(I)-F] ign=$opts[(I)-F]
if (( ign )); then if (( ign )); then
ign=( $=opts[ign+1] ) ign=( $=opts[ign+1] )
@ -20,56 +20,59 @@ else
fi fi
if zstyle -a ":completion:${curcontext}:" file-patterns tmp; then if zstyle -a ":completion:${curcontext}:" file-patterns tmp; then
[[ "$type" = */* ]] && glob="$glob *(-/)" [[ "$type" = */* ]] && glob="$glob,*(-/)"
pats=() pats=()
for i in ${tmp//\\%p/ ${${glob:-\*}//:/\\:} }; do for i in ${tmp//\\%p/ ${${glob:-\*}//:/\\:} }; do
if [[ $i = *[^\\]:* ]]; then if [[ $i = *[^\\]:* ]]; then
pats=( "$pats[@]" " $i" ) pats=( "$pats[@]" " $i " )
else else
pats=( "$pats[@]" " ${i}:files" ) pats=( "$pats[@]" " ${i}:files " )
fi fi
done done
else else
if [[ "$type" = *g* ]]; then if [[ "$type" = *g* ]]; then
if [[ "$type" = */* ]]; then if [[ "$type" = */* ]]; then
pats=( " ${glob//:/\\:} *(-/):globbed-files" '*:all-files' ) pats=( " ${glob//:/\\:}:globbed-files *(-/):directories" '*:all-files ' )
else else
pats=( " ${glob//:/\\:}:globbed-files" pats=( " ${glob//:/\\:}:globbed-files "
'*(-/):directories' '*:all-files' ) '*(-/):directories ' '*:all-files ' )
fi fi
elif [[ "$type" = */* ]]; then elif [[ "$type" = */* ]]; then
pats=( '*(-/):directories' '*:all-files' ) pats=( '*(-/):directories ' '*:all-files ' )
else else
pats=( '*:all-files' ) pats=( '*:all-files ' )
fi fi
fi fi
for def in "$pats[@]"; do ###"${(@)${(@)pats#*[^\\]:}%%:*}"; do for def in "$pats[@]"; do
def="${def##[[:blank:]]#}"
while [[ "$def" = *[^\\][[:blank:]]* ]]; do
sdef="${(M)def#*[^\\][[:blank:]]}"
tag="${${sdef#*[^\\]:}%%:*}"
pat="${${${sdef%%:${tag}*}//\\\\:/:}//,/ }"
tag="${${def#*[^\\]:}%%:*}" if [[ "$sdef" = *:${tag}:* ]]; then
pat="${${def%%:${tag}*}//\\\\:/:}" descr="${(Q)sdef#*:${tag}:}"
if [[ "$pat" != \ # ]]; then
if [[ "$def" = *:${tag}:* ]]; then
descr="${def#*:${tag}:}"
else else
descr=file descr=file
end=yes end=yes
fi fi
fi
if _wanted "$tag"; then _tags "$tag"
_comp_ignore=() while _tags; do
while _next_label "$tag" expl "$descr"; do _comp_ignore=()
_comp_ignore=( $_comp_ignore $ign ) while _next_label "$tag" expl "$descr"; do
if [[ -n "$end" ]]; then _comp_ignore=( $_comp_ignore $ign )
_path_files -g "$pat" "$opts[@]" "$expl[@]" && ret=0 if [[ -n "$end" ]]; then
else _path_files -g "$pat" "$opts[@]" "$expl[@]" && ret=0
_path_files "$expl[@]" -g "$pat" "$opts[@]" && ret=0 else
fi _path_files "$expl[@]" -g "$pat" "$opts[@]" && ret=0
fi
done
done done
(( ret )) || return 0 def="${${def#${sdef}}##[[:blank:]]#}"
fi done
(( ret )) || return 0
done done
return 1 return 1

View file

@ -1,13 +1,14 @@
#autoload #autoload
local gopt=-J descr local gopt=-J descr spec
if [[ "$1" = -([12]|)[VJ] ]]; then if [[ "$1" = -([12]|)[VJ] ]]; then
gopt="$1" gopt="$1"
shift shift
fi fi
if comptags -A "$1" curtag; then if comptags -A "$1" curtag spec; then
_comp_tags="$_comp_tags $spec "
if [[ "$curtag" = *:* ]]; then if [[ "$curtag" = *:* ]]; then
zformat -f descr "${curtag#*:}" "d:$3" zformat -f descr "${curtag#*:}" "d:$3"
_description "$gopt" "${curtag%:*}" "$2" "$descr" _description "$gopt" "${curtag%:*}" "$2" "$descr"

View file

@ -8,7 +8,6 @@ if [[ "$1" = -([12]|)[VJ] ]]; then
fi fi
if comptags -R "$1"; then if comptags -R "$1"; then
_comp_tags="$_comp_tags $1"
if [[ $# -gt 3 ]]; then if [[ $# -gt 3 ]]; then
_all_labels "$gopt" "$@" _all_labels "$gopt" "$@"
elif [[ $# -gt 1 ]]; then elif [[ $# -gt 1 ]]; then

View file

@ -17,17 +17,10 @@ if [[ "$1" = -([12]|)[VJ] ]]; then
shift shift
fi fi
if [[ $# -gt 3 ]]; then _tags "$targs[@]" "$1"
if _tags "$targs[@]" "$1"; then
_comp_tags="$_comp_tags $1"
_all_labels -t "$gopt" "$@" while _tags; do
else _all_labels "$gopt" "$@" && return 0
return 1 done
fi
elif [[ $# -gt 1 ]]; then return 1
_tags -- "$targs[@]" "$1" && _comp_tags="$_comp_tags $1" &&
_description "$gopt" "$@"
else
_tags -- "$targs[@]" "$1" && _comp_tags="$_comp_tags $1"
fi

View file

@ -75,7 +75,7 @@ _apt_arguments () {
nul=$'\0' nul=$'\0'
qnul="\$'\\0'" qnul="\$'\\0'"
comp_bool='_wanted values && compadd "$expl_bool[@]" '"$bool" comp_bool='_wanted values expl_bool "boolean value" compadd "$expl_bool[@]" '"$bool"
comp_intlevel= #"_message 'intlevel'" comp_intlevel= #"_message 'intlevel'"
comp_configfile='_files "$expl_configfile[@]"' comp_configfile='_files "$expl_configfile[@]"'
comp_arbitem= #"_message 'Foo::Bar=bar'" comp_arbitem= #"_message 'Foo::Bar=bar'"

View file

@ -1,7 +1,57 @@
#autoload #autoload
if (( ! $+_deb_packages )); then # Usage: _deb_packages expl... avail|installed|uninstalled
_deb_packages=( $(awk '/^Package:/ { print $2 }' /var/lib/dpkg/status) )
fi
compadd "$@" - $_deb_packages _deb_packages_update_avail () {
if (( ! $+_deb_packages_cache_avail )); then
_deb_packages_cache_avail=(
${(f)"$(apt-cache dumpavail | awk '/^Package:/ { print $2 }')"}
)
fi
cachevar=_deb_packages_cache_avail
}
_deb_packages_update_installed () {
if (( ! $+_deb_packages_cache_installed )); then
_deb_packages_cache_installed=(
${${${(f)"$(dpkg --get-selections)"}:#*deinstall}%% *}
)
fi
cachevar=_deb_packages_cache_installed
}
_deb_packages_update_uninstalled () {
_deb_packages_update_avail
_deb_packages_update_installed
if (( ! $+_deb_packages_cache_uninstalled )); then
_deb_packages_cache_uninstalled=(
${_deb_packages_cache_avail:#${(j:|:)~${_deb_packages_cache_installed:q}}}
)
fi
cachevar=_deb_packages_cache_uninstalled
}
_deb_packages () {
local command="$argv[$#]" expl cachevar pkgset
[[ "$command" = (installed|uninstalled|avail) ]] || {
_message "_deb_packages:unknown command: $command"
return
}
zstyle -s ":completion:${curcontext}:" packageset pkgset
[[ "$pkgset" = (installed|uninstalled|avail|available) ]] || {
pkgset="$command"
}
[[ "$pkgset" = "available" ]] && pkgset="avail"
expl=("${(@)argv[1,-2]}")
_deb_packages_update_$pkgset
_tags packages && compadd "$expl[@]" - "${(@P)cachevar}"
}
_deb_packages "$@"

File diff suppressed because it is too large Load diff

View file

@ -17,7 +17,8 @@ elif compset -P '-(exec|se)='; then
elif compset -P '-(symbols|core|command)='; then elif compset -P '-(symbols|core|command)='; then
_files _files
elif [[ "$PREFIX" = -* ]]; then elif [[ "$PREFIX" = -* ]]; then
if _wanted options; then _tags options
while _tags; do
while _next_label options expl option; do while _next_label options expl option; do
compadd "$expl[@]" -QS '' - -symbols\= -exec\= -se\= -core\= -command\= \ compadd "$expl[@]" -QS '' - -symbols\= -exec\= -se\= -core\= -command\= \
-directory\= -cd\= -tty\= && ret=0 -directory\= -cd\= -tty\= && ret=0
@ -25,7 +26,7 @@ elif [[ "$PREFIX" = -* ]]; then
-batch -fullname -f -b && ret=0 -batch -fullname -f -b && ret=0
done done
(( ret )) || return 0 (( ret )) || return 0
fi done
else else
prev="$words[CURRENT-1]" prev="$words[CURRENT-1]"

View file

@ -1,12 +1,58 @@
#compdef gprof #compdef gprof
_arguments -s -{a,b,c,D,h,i,l,L,s,T,v,w,x,y,z} \ local curcontext="$curcontext" state line ret=1
-{A,C,e,E,f,F,J,n,N,O,p,P,q,Q,Z}:'function name: _exec_funcs' \ typeset -A opt_args
_arguments -C -s -{a,b,c,D,h,i,l,L,s,T,v,w,x,y,z} \
-{A,C,e,E,f,F,J,n,N,O,p,P,q,Q,Z}:'function name:->funcs' \
'-I:directory:_dir_list' \ '-I:directory:_dir_list' \
'-d-:debug level:' '-k:function names: _exec_funcs -p' \ '-d-:debug level:' '-k:function names:->pair' \
'-m:minimum execution count:' \ '-m:minimum execution count:' \
':executable:_files -g *(*)' \ ':executable:_files -g \*\(\*\)' \
':profile file:_files -g gmon.*' \ ':profile file:_files -g gmon.\*' \
-- -s '(#--[no-] --)' \ -- -s '(#--[no-] --)' \
'*=name*:function name: _exec_funcs' \ '*=name*:function name:->funcs' \
'*=dirs*:directory:_dir_list' '*=dirs*:directory:_dir_list' && ret=0
if [[ -n "$state" ]]; then
local cmd pair expl
_tags functions || return 1
[[ "$state" = pair ]] && pair=yes
if [[ $#line -gt 1 ]]; then
cmd="$line[2]"
else
return 1
fi
if [[ -n "$cmd" ]]; then
if [[ "$cmd" = /* ]]; then
tmp="$cmd"
else
tmp="$PWD/$cmd"
fi
if [[ "$tmp" != "$_gprof_command" ]]; then
_gprof_command="$tmp"
_gprof_funcs=( "${(@)${(@M)${(@f)$(nm $cmd)}:#[^ ]# [tT] ([^_]|_[^_])*}##* }" )
fi
if [[ -n "$pair" ]]; then
if compset -P '*/'; then
expl='call arc to function'
else
expl='call arc from function'
fi
else
expl=function
fi
_wanted functions expl "$expl" \
compadd "$expl[@]" -M 'r:|_=* r:|=*' - "$_gprof_funcs[@]" && ret=0
else
return 1
fi
fi
return ret

View file

@ -2,7 +2,7 @@
local expl groups tmp local expl groups tmp
_wanted groups || return 1 _tags groups || return 1
if ! zstyle -a ":completion:${curcontext}:" groups groups; then if ! zstyle -a ":completion:${curcontext}:" groups groups; then
(( $+_cache_groups )) || (( $+_cache_groups )) ||
@ -16,4 +16,4 @@ if ! zstyle -a ":completion:${curcontext}:" groups groups; then
groups=( "$_cache_groups[@]" ) groups=( "$_cache_groups[@]" )
fi fi
_all_labels groups expl group compadd "$@" - "$groups[@]" _wanted groups expl group compadd "$@" - "$groups[@]"

View file

@ -36,28 +36,27 @@ if (( ! $+_lp_cache )); then
fi fi
if compset -P -P || [[ "$words[CURRENT-1]" = -P ]]; then if compset -P -P || [[ "$words[CURRENT-1]" = -P ]]; then
if _wanted printers; then if zstyle -T ":completion:${curcontext}:printers" verbose; then
if zstyle -T ":completion:${curcontext}:printers" verbose; then zformat -a list ' -- ' "$_lp_cache[@]"
zformat -a list ' -- ' "$_lp_cache[@]" disp=(-ld list)
disp=(-ld list)
else
disp=()
fi
_all_labels printers expl printer \
compadd "$disp[@]" - "${(@)_lp_cache%%:*}" && return 0
(( $+_lp_alias_cache )) || return 1
if zstyle -T ":completion:${curcontext}:printers" verbose; then
zformat -a list ' -- ' "$_lp_alias_cache[@]"
disp=(-ld list)
else
disp=()
fi
compadd "$expl[@]" "$disp[@]" - "${(@)_lp_alias_cache%%:*}"
else else
return 1 disp=()
fi fi
_wanted printers expl printer \
compadd "$disp[@]" - "${(@)_lp_cache%%:*}" && return 0
(( $+_lp_alias_cache )) || return 1
if zstyle -T ":completion:${curcontext}:printers" verbose; then
zformat -a list ' -- ' "$_lp_alias_cache[@]"
disp=(-ld list)
else
disp=()
fi
_wanted printers expl printer \
compadd "$disp[@]" - "${(@)_lp_alias_cache%%:*}" && return 0
return 1
else else
if [[ "${words[1]:t}" = (lpq|lprm) ]]; then if [[ "${words[1]:t}" = (lpq|lprm) ]]; then
if [[ "$words" = *-P* ]]; then if [[ "$words" = *-P* ]]; then

View file

@ -17,16 +17,13 @@ if compset -P 1 -; then
# get list of options, which MH commands can generate themselves # get list of options, which MH commands can generate themselves
# awk is just too icky to use for this, sorry. send me one if # awk is just too icky to use for this, sorry. send me one if
# you come up with it. # you come up with it.
if _wanted options; then _wanted options expl option \
_all_labels options expl option \ compadd - $($words[1] -help | perl -ne 'if (/^\s*-\(?(\S+)/) {
compadd - $($words[1] -help | perl -ne 'if (/^\s*-\(?(\S+)/) {
$n = $1; $n = $1;
$n =~ s/\)//g; $n =~ s/\)//g;
print $n =~ s/^\[([a-z]+)\]// ? "$n\n$1$n\n" : "$n\n"; print $n =~ s/^\[([a-z]+)\]// ? "$n\n$1$n\n" : "$n\n";
}') }')
return return
fi
return 1
elif compset -P 1 '[+@]' || [[ "$prev" = -draftfolder ]]; then elif compset -P 1 '[+@]' || [[ "$prev" = -draftfolder ]]; then
# Complete folder names. # Complete folder names.
local mhpath local mhpath
@ -72,13 +69,15 @@ else
# leaving foldnam empty works here # leaving foldnam empty works here
fi fi
if _wanted sequences; then _tags sequences
while _tags; do
while _next_label sequences expl sequence; do while _next_label sequences expl sequence; do
compadd "$expl[@]" $(mark $foldnam 2>/dev/null | awk -F: '{ print $1 }') && compadd "$expl[@]" $(mark $foldnam 2>/dev/null | awk -F: '{ print $1 }') &&
ret=0 ret=0
compadd "$expl[@]" reply next cur prev first last all unseen && ret=0 compadd "$expl[@]" reply next cur prev first last all unseen && ret=0
_files "$expl[@]" -W folddir -g '<->' && ret=0 _files "$expl[@]" -W folddir -g '<->' && ret=0
done done
fi (( ret )) || return 0
done
return ret return ret
fi fi

View file

@ -543,7 +543,7 @@ fstype)
compadd "$expl[@]" -qS, -M 'L:|no=' - "$fss[@]" && ret=0 compadd "$expl[@]" -qS, -M 'L:|no=' - "$fss[@]" && ret=0
;; ;;
fsopt) fsopt)
_wanted options || return 1 _tags options || return 1
eval 'tmp=(' '"$_fs_'${(s:,:)^${opt_args[$typeops]:-${deffs}}}'[@]"' ')' eval 'tmp=(' '"$_fs_'${(s:,:)^${opt_args[$typeops]:-${deffs}}}'[@]"' ')'
tmp=( "$_fs_any[@]" "${(@)tmp:#}" ) tmp=( "$_fs_any[@]" "${(@)tmp:#}" )

View file

@ -56,16 +56,14 @@ if [[ "$state" = "remote" ]]; then
fi fi
;; ;;
*) *)
if _wanted commands; then if [[ -z "$QIPREFIX" ]]; then
if [[ -z "$QIPREFIX" ]]; then _wanted commands expl 'remote commands' \
_all_labels commands expl 'remote commands' \ compadd -s'(' -S '' -M 'm:{a-zA-Z}={A-Za-z}' - \
compadd -s'(' -S '' -M 'm:{a-zA-Z}={A-Za-z}' - \ $remote_commands && ret=0
$remote_commands && ret=0 else
else _wanted commands expl 'remote commands' \
_all_labels commands expl 'remote commands' \ compadd -qS '(' -M 'm:{a-zA-Z}={A-Za-z}' - \
compadd -qS '(' -M 'm:{a-zA-Z}={A-Za-z}' - \ $remote_commands && ret=0
$remote_commands && ret=0
fi
fi fi
;; ;;
esac esac
@ -78,12 +76,14 @@ if [[ "$state" = "urls" ]]; then
compadd authors blank cache document fonts global hype image-cache \ compadd authors blank cache document fonts global hype image-cache \
license logo memory-cache mozilla plugins && ret=0 license logo memory-cache mozilla plugins && ret=0
else else
if _wanted prefixes; then _tags prefixes
while _tags; do
while _next_label prefixes expl 'URL prefix'; do while _next_label prefixes expl 'URL prefix'; do
compadd "$expl[@]" -S '' about: mocha: javascript: && ret=0 compadd "$expl[@]" -S '' about: mocha: javascript: && ret=0
_urls "$@" && ret=0 _urls "$@" && ret=0
done done
fi (( ret )) || return 0
done
fi fi
fi fi

View file

@ -19,9 +19,7 @@
# other characters than lower case letters, we try to call the function # other characters than lower case letters, we try to call the function
# `_nslookup_host'. # `_nslookup_host'.
setopt localoptions extendedglob local context curstate="$curcontext" expl ret=1 setopts
local state expl ret=1 setopts
setopts=( setopts=(
'all[print current values]' \ 'all[print current values]' \
@ -40,7 +38,7 @@ setopts=(
'(noignoretc)ignoretc[ignore packet truncation errors]' \ '(noignoretc)ignoretc[ignore packet truncation errors]' \
'(ignoretc)noignoretc[don'"'"'t ignore packet truncation errors]' \ '(ignoretc)noignoretc[don'"'"'t ignore packet truncation errors]' \
'class[change query class]:query class:((in\:Internet\ class chaos\:CHAOS\ class hesiod\:MIT\ Athena\ Hesiod\ class any\:wildcard\ \(any\ of\ the\ above\)))' 'class[change query class]:query class:((in\:Internet\ class chaos\:CHAOS\ class hesiod\:MIT\ Athena\ Hesiod\ class any\:wildcard\ \(any\ of\ the\ above\)))'
'domain[change default domain]:default domain:_hosts' "domain[change default domain]:default domain:_domains"
'srchlist[change default domain and search list]: :->srchlist' 'srchlist[change default domain and search list]: :->srchlist'
'port[change name server port]:name server port:' 'port[change name server port]:name server port:'
{query,}type'[change type of information query]:query information type:((a\:internet\ address cname\:canonical\ name\ for\ alias hinfo\:CPU\ and\ operating\ system\ type minfo\:mailbox\ or\ mail\ list\ information mx\:mail\ exchanger ns\:name\ server\ for\ zone ptr\:host\ name\ or\ other\ information soa\:domain\'"'"'s\ \`start-of-authority\'"'"'\ information txt\:text\ information uinfo\:user\ information wks\:supported\ well-known\ services))' {query,}type'[change type of information query]:query information type:((a\:internet\ address cname\:canonical\ name\ for\ alias hinfo\:CPU\ and\ operating\ system\ type minfo\:mailbox\ or\ mail\ list\ information mx\:mail\ exchanger ns\:name\ server\ for\ zone ptr\:host\ name\ or\ other\ information soa\:domain\'"'"'s\ \`start-of-authority\'"'"'\ information txt\:text\ information uinfo\:user\ information wks\:supported\ well-known\ services))'
@ -52,23 +50,25 @@ setopts=(
if [[ -n "$compcontext" ]]; then if [[ -n "$compcontext" ]]; then
if [[ CURRENT -eq 1 ]]; then if [[ CURRENT -eq 1 ]]; then
funcall ret _nslookup_command && return ret _funcall ret _nslookup_command && return ret
_description expl 'command' _alternative \
compadd "$expl[@]" - server lserver root finger ls view help set && ret=0 'commands:command:(server lserver root finger ls view help set exit)' \
_hosts && ret=0 'hosts:: _hosts' && ret=0
return ret return ret
elif [[ "$compstate[context]" = redirect ]]; then elif [[ "$compstate[context]" = redirect ]]; then
funcall ret _nslookup_redirect && return ret _funcall ret _nslookup_redirect && return ret
_tags -C redirection files || return 1
if [[ "$words[1]" != (finger|ls) ]]; then if [[ "$words[1]" != (finger|ls) ]]; then
_message "redirection not allowed for command \`$words[1]'" _message "redirection not allowed for command \`$words[1]'"
return 1 return 1
elif [[ "$compstate[redirect]" = '>' ]]; then elif [[ "$compstate[redirect]" = '>' ]]; then
_description expl 'write to file' _description files expl 'write to file'
elif [[ "$compstate[redirect]" = '>>' ]]; then elif [[ "$compstate[redirect]" = '>>' ]]; then
_description expl 'append to file' _description files expl 'append to file'
else else
_message "unknown redirection operator \`$compstate[redirect]'" _message "unknown redirection operator \`$compstate[redirect]'"
return 1 return 1
@ -79,15 +79,14 @@ if [[ -n "$compcontext" ]]; then
fi fi
if [[ "$words[1]" = [a-z]## ]]; then if [[ "$words[1]" = [a-z]## ]]; then
funcall ret _nslookup_$words[1] && return ret _funcall ret _nslookup_$words[1] && return ret
else else
funcall ret _nslookup_host && return ret _funcall ret _nslookup_host && return ret
fi fi
case "$words[1]" in case "$words[1]" in
(|l)server) (|l)server)
_description expl 'new default server' _wanted hosts expl 'new default server' _hosts
_hosts "$expl[@]"
return return
;; ;;
root|exit|help|\?) root|exit|help|\?)
@ -104,24 +103,23 @@ if [[ -n "$compcontext" ]]; then
'-d[all records]' \ '-d[all records]' \
'-h[CPU and operating system information]' \ '-h[CPU and operating system information]' \
'-s[well-known services]' \ '-s[well-known services]' \
':domain:_hosts' ":domain:_domains"
return return
;; ;;
view) view)
_description expl 'view file' _description files expl 'view file'
_files "$expl[@]" _files "$expl[@]"
return return
;; ;;
set) set)
typeset -A values typeset -A val_args
_values 'state information' "$setopts[@]" && ret=0 _values 'state information' "$setopts[@]" && ret=0
[[ -z "$state" ]] && return ret [[ -z "$state" ]] && return ret
;; ;;
*) *)
_description expl 'server' _wanted hosts expl 'server' _hosts
_hosts "$expl[@]"
return return
esac esac
fi fi
@ -130,9 +128,9 @@ fi
if [[ -z "$state" ]]; then if [[ -z "$state" ]]; then
local line local line
typeset -A options typeset -A opt_args
_arguments \ _arguments -C \
"-${(@)^${(@M)setopts:#*\]:*}/\[/=[}" \ "-${(@)^${(@M)setopts:#*\]:*}/\[/=[}" \
"-${(@)^setopts:#(\(|*\]:)*}" \ "-${(@)^setopts:#(\(|*\]:)*}" \
"${(@)^${(@)${(@M)setopts:#\(*}/\)/)-}/\(/(-}" \ "${(@)^${(@)${(@M)setopts:#\(*}/\)/)-}/\(/(-}" \
@ -143,15 +141,17 @@ fi
# This is completion after `srchlist' for both types. # This is completion after `srchlist' for both types.
if [[ -n "$state" ]]; then if [[ -n "$state" ]]; then
_tags domains || return 1
if compset -P '*/'; then if compset -P '*/'; then
_description expl 'search list entry' _description domains expl 'search list entry'
else else
_description expl 'default domain name and first search list entry' _description domains expl 'default domain name and first search list entry'
fi fi
if [[ -n "$_vals_cache_multi" ]]; then if [[ -n "$_vals_cache_multi" ]]; then
_hosts "$expl[@]" -qS/ -r "/\\- \\t\\n$_vals_cache_multi" _domains "$expl[@]" -qS/ -r "/\\- \\t\\n$_vals_cache_multi"
else else
_hosts "$expl[@]" -qS/ _domains "$expl[@]" -qS/
fi fi
return return
fi fi

View file

@ -28,7 +28,7 @@ _rlogin () {
return ret return ret
;; ;;
rcp) rcp)
local curcontext="$curcontext" state line ret=1 local curcontext="$curcontext" state line ret=1 expl
typeset -A opt_args typeset -A opt_args
_arguments -C -s \ _arguments -C -s \
@ -40,7 +40,7 @@ _rlogin () {
if compset -P '*:'; then if compset -P '*:'; then
_files && ret=0 _files && ret=0
elif compset -P '*@'; then elif compset -P '*@'; then
_wanted hosts && _rlogin_hosts -S: -q && ret=0 _wanted hosts expl host _rlogin_hosts -S: -q && ret=0
else else
_alternative \ _alternative \
'files:: _files' \ 'files:: _files' \
@ -54,11 +54,11 @@ _rlogin () {
} }
_rlogin_users () { _rlogin_users () {
_wanted users && _combination -s '[:@]' my-accounts users-hosts users "$@" _tags users && _combination -s '[:@]' my-accounts users-hosts users "$@"
} }
_rlogin_hosts () { _rlogin_hosts () {
_wanted hosts && _tags hosts &&
if [[ "$IPREFIX" == *@ ]]; then if [[ "$IPREFIX" == *@ ]]; then
_combination -s '[:@]' my-accounts users-hosts "users=${IPREFIX/@}" hosts "$@" _combination -s '[:@]' my-accounts users-hosts "users=${IPREFIX/@}" hosts "$@"
else else

View file

@ -1,34 +1,55 @@
#compdef socket #compdef socket
local state line expl # Style used:
typeset -A options #
# hosts-ports
# The style that contains pairs `host:port'.
_arguments -s \ local curcontext="$curcontext" state line expl
-{b,c,f,q,r,v,w} \ typeset -A opt_args
-{s,l} \
'-p:command:->command' \ [[ $CURRENT -eq 2 ]] &&
{ ! zstyle -T ":completion:${curcontext}:options" prefix-needed ||
[[ "$PREFIX" = -* ]] } &&
_wanted options expl option \
compadd -M 'r:|[_-]=* r:|=*' "$expl[@]" - -version
_arguments -C -s \
'-b[background]' \
'-c[crlf]' \
'-f[fork]' \
'-q[quit]' \
'-r[read only]' \
'-v[verbose]' \
'-w[write only]' \
'-s[server]' \
'-l[loop]' \
'-p[program]:command:->command' \
':arg1:->arg1' \ ':arg1:->arg1' \
':arg2:->arg2' ':arg2:->arg2'
case "$state" in case "$state" in
command) command)
compset -q compset -q
_normal if [[ $CURRENT -eq 1 ]]; then
_command_names -e "$@"
else
_normal
fi
;; ;;
arg1) arg1)
if (( $+options[-s] )); then if (( $+opt_args[-s] )); then
_message 'port' _ports
else else
_description expl 'host' _wanted hosts expl 'host' _combination '' hosts-ports hosts -
_hosts "$expl[@]"
fi fi
;; ;;
arg2) arg2)
if (( ! $+options[-s] )); then if (( ! $+opt_args[-s] )); then
_description expl 'port' _wanted ports expl 'port to connect' \
_hostports $line[2] "$expl[@]" _combination '' hosts-ports hosts="${line[1]:q}" ports -
fi fi
;; ;;
esac esac

View file

@ -195,12 +195,14 @@ if [[ -n "$state" ]]; then
;; ;;
esac esac
else else
if _wanted values; then _tags values
while _tags; do
while _next_label values expl 'compression scheme'; do while _next_label values expl 'compression scheme'; do
compadd "$expl[@]" - none g4 packbits && ret=0 compadd "$expl[@]" - none g4 packbits && ret=0
compadd "$expl[@]" -qS: - lzw zip jpeg g3 && ret=0 compadd "$expl[@]" -qS: - lzw zip jpeg g3 && ret=0
done done
fi (( ret )) || return 0
done
fi fi
fi fi

View file

@ -49,18 +49,22 @@ local localhttp_userdir="$localhttp[3]"
if [[ "$1" = -f ]]; then if [[ "$1" = -f ]]; then
shift shift
_wanted -C -f files && _files "$@" && return _wanted -C -f files _files "$@" && return 0
fi fi
ipre="$IPREFIX" ipre="$IPREFIX"
if ! compset -P '(#b)([-+.a-z0-9]#):' && _wanted -C argument prefixes; then if ! compset -P '(#b)([-+.a-z0-9]#):'; then
while _next_label prefixes expl 'URL prefix' "$@"; do _tags -C argument prefixes
[[ -d $urls_path/bookmark ]] && while _tags; do
compadd "$expl[@]" -S '' bookmark: && ret=0 while _next_label prefixes expl 'URL prefix' "$@"; do
compadd "$expl[@]" -S '' file: ftp:// gopher:// http:// && ret=0 [[ -d $urls_path/bookmark ]] &&
compadd "$expl[@]" -S '' bookmark: && ret=0
compadd "$expl[@]" -S '' file: ftp:// gopher:// http:// && ret=0
done
(( ret )) || return 0
done done
return ret return 1
fi fi
scheme="$match[1]" scheme="$match[1]"
@ -73,17 +77,19 @@ case "$scheme" in
;; ;;
file) file)
if ! compset -P //; then if ! compset -P //; then
_wanted -C file files || return 1 _tags -C file files
while _tags; do
while _next_label files expl 'local file' "$@"; do while _next_label files expl 'local file' "$@"; do
if [[ -prefix / ]]; then if [[ -prefix / ]]; then
_path_files "$expl[@]" -S '' -g '*(^/)' && ret=0 _path_files "$expl[@]" -S '' -g '*(^/)' && ret=0
_path_files "$expl[@]" -S/ -r '/' -/ && ret=0 _path_files "$expl[@]" -S/ -r '/' -/ && ret=0
elif [[ -z "$PREFIX" ]]; then elif [[ -z "$PREFIX" ]]; then
compadd "$expl[@]" -S '/' -r '/' - "${PWD%/}" && ret=0 compadd "$expl[@]" -S '/' -r '/' - "${PWD%/}" && ret=0
fi fi
done
(( ret )) || return 0
done done
return ret return 1
fi fi
;; ;;
bookmark) bookmark)
@ -93,34 +99,40 @@ case "$scheme" in
compadd "$@" -U - \ compadd "$@" -U - \
"$ipre$(<"$urls_path/$scheme/${(Q)PREFIX}${(Q)SUFFIX}")" && ret=0 "$ipre$(<"$urls_path/$scheme/${(Q)PREFIX}${(Q)SUFFIX}")" && ret=0
else else
if _wanted -C bookmark files; then _tags -C bookmark files
while _tags; do
while _next_label files expl 'bookmark'; do while _next_label files expl 'bookmark'; do
_path_files -W "$urls_path/$scheme" "$expl[@]" -S '' -g '*(^/)' && _path_files -W "$urls_path/$scheme" "$expl[@]" -S '' -g '*(^/)' &&
ret=0 ret=0
_path_files -W "$urls_path/$scheme" -S/ -r '/' -/ && ret=0 _path_files -W "$urls_path/$scheme" -S/ -r '/' -/ && ret=0
done done
fi (( ret )) || return 0
done
fi fi
return ret return ret
;; ;;
esac esac
# Complete hosts # Complete hosts
if ! compset -P '(#b)([^/]#)/' && _wanted hosts; then if ! compset -P '(#b)([^/]#)/'; then
uhosts=($urls_path/$scheme/$PREFIX*$SUFFIX(/:t)) uhosts=($urls_path/$scheme/$PREFIX*$SUFFIX(/:t))
while _next_label hosts expl host "$@"; do _tags hosts
(( $#uhosts )) || _hosts -S/ && ret=0 while _tags; do
[[ "$scheme" = http ]] && uhosts=($uhosts $localhttp_servername) while _next_label hosts expl host "$@"; do
compadd "$expl[@]" -S/ - $uhosts && ret=0 (( $#uhosts )) || _hosts -S/ && ret=0
[[ "$scheme" = http ]] && uhosts=($uhosts $localhttp_servername)
compadd "$expl[@]" -S/ - $uhosts && ret=0
done
(( ret )) || return 0
done done
return ret return 1
fi fi
host="$match[1]" host="$match[1]"
# Complete part after hostname # Complete part after hostname
_wanted -C local files || return 1 _tags -C local files || return 1
if [[ "$localhttp_servername" = "$host" ]]; then if [[ "$localhttp_servername" = "$host" ]]; then
if compset -P \~; then if compset -P \~; then
@ -129,20 +141,29 @@ if [[ "$localhttp_servername" = "$host" ]]; then
return return
fi fi
user="$match[1]" user="$match[1]"
while _next_label files expl 'local file'; do while _tags; do
_path_files "$expl[@]" -W ~$user/$localhttp_userdir -g '*(^/)' && ret=0 while _next_label files expl 'local file'; do
_path_files "$expl[@]" -W ~$user/$localhttp_userdir -S/ -r '/' -/ && ret=0 _path_files "$expl[@]" -W ~$user/$localhttp_userdir -g '*(^/)' && ret=0
_path_files "$expl[@]" -W ~$user/$localhttp_userdir -S/ -r '/' -/ && ret=0
done
(( ret )) || return 0
done done
else else
while _next_label files expl 'local file'; do while _tags; do
_path_files "$expl[@]" -W $localhttp_documentroot -g '*(^/)' && ret=0 while _next_label files expl 'local file'; do
_path_files "$expl[@]" -W $localhttp_documentroot -S/ -r '/' -/ && ret=0 _path_files "$expl[@]" -W $localhttp_documentroot -g '*(^/)' && ret=0
_path_files "$expl[@]" -W $localhttp_documentroot -S/ -r '/' -/ && ret=0
done
(( ret )) || return 0
done done
fi fi
else else
while _next_label files expl 'local file'; do while _tags; do
_path_files "$expl[@]" -W $urls_path/$scheme/$host -g '*(^/)' && ret=0 while _next_label files expl 'local file'; do
_path_files "$expl[@]" -W $urls_path/$scheme/$host -S/ -r '/' -/ && ret=0 _path_files "$expl[@]" -W $urls_path/$scheme/$host -g '*(^/)' && ret=0
_path_files "$expl[@]" -W $urls_path/$scheme/$host -S/ -r '/' -/ && ret=0
done
(( ret )) || return 0
done done
fi fi
return $ret return $ret

View file

@ -2,9 +2,7 @@
local expl users local expl users
_wanted users || return 1
zstyle -a ":completion:${curcontext}:" users users && zstyle -a ":completion:${curcontext}:" users users &&
_all_labels users expl user compadd "$@" - "$users[@]" && return 0 _wanted users expl user compadd "$@" - "$users[@]" && return 0
_all_labels users expl user compadd "$@" - "${(@k)userdirs}" _wanted users expl user compadd "$@" - "${(@k)userdirs}"

View file

@ -2,10 +2,8 @@
local expl local expl
_wanted users || return 1 if (( $+commands[users] )); then
_wanted users expl 'users logged on' \
if which users >/dev/null; then
_all_labels users expl 'users logged on' \
compadd "$@" - $(_call users users) && return 0 compadd "$@" - $(_call users users) && return 0
else else
# Other methods of finding out users logged on should be added here # Other methods of finding out users logged on should be added here

View file

@ -1,12 +1,14 @@
#compdef whois #compdef whois fwhois
_whois () { _whois () {
setopt localoptions extendedglob
_whois_setup _whois_setup
$_whois_comp case "$0" in
fwhois) _whois_fwhois;;
*) $_whois_comp;;
esac
} }
builtin functions _whois_setup >&- || (( $+functions[_whois_setup] )) ||
_whois_setup () { _whois_setup () {
(( $+_whois_defaultserver )) || (( $+_whois_defaultserver )) ||
_whois_defaultserver='whois.internic.net' _whois_defaultserver='whois.internic.net'
@ -65,6 +67,7 @@ _whois_setup () {
(( $+_whois_arguments )) || { (( $+_whois_arguments )) || {
local help="$(whois </dev/null 2>&1)" local help="$(whois </dev/null 2>&1)"
local tmp opt opts local tmp opt opts
local hostopt=-h+
if [[ $help = *"user[@<whois.server>]"* ]]; then if [[ $help = *"user[@<whois.server>]"* ]]; then
_whois_comp=_whois_fwhois _whois_comp=_whois_fwhois
@ -72,6 +75,7 @@ _whois_setup () {
_whois_comp=_whois_multi _whois_comp=_whois_multi
else else
_whois_comp=_whois_single _whois_comp=_whois_single
hostopt=-h
fi fi
_whois_arguments=() _whois_arguments=()
@ -96,25 +100,29 @@ _whois_setup () {
for opt in $tmp; do for opt in $tmp; do
opts=(-${^tmp:#$opt}) opts=(-${^tmp:#$opt})
if (( $#opts )); then opts="($opts)"; else opts=; fi if (( $#opts )); then opts="($opts)"; else opts=; fi
_whois_arguments=("$_whois_arguments[@]" if [[ $opt = h ]]; then
"${opts}-${opt}[${${${(@M)_whois_servers:#*:$opt}%:?}:-specify host}]${(M)${(M)opt:#h}/h/:host:_whois_hosts}" _whois_arguments=("$_whois_arguments[@]"
) "${opts}${hostopt}:host:_whois_hosts")
else
_whois_arguments=("$_whois_arguments[@]"
"${opts}-${opt}[${${(@M)_whois_servers:#*:$opt}%:?}]")
fi
done done
} }
} }
_whois_single () { _whois_single () {
local state line expl local curcontext="$curcontext" state line expl
typeset -A opt_args typeset -A opt_args
local tmp host local tmp host
_arguments \ _arguments -C \
"$_whois_arguments[@]" \ "$_whois_arguments[@]" \
':identifier:->identifier' ':identifier:->identifier'
case "$state" in case "$state" in
identifier) identifier)
if [[ -z "$QIPREFIX" ]]; then if [[ -z "$QIPREFIX" && -z "$PREFIX" ]]; then
compadd -QS '' \' compadd -QS '' \'
return return
fi fi
@ -126,7 +134,7 @@ _whois_single () {
break break
fi fi
done done
if builtin functions "_whois:$host" >&-; then if (( $+functions[_whois:$host] )); then
"_whois:$host" "$expl[@]" "_whois:$host" "$expl[@]"
else else
_message "identifier" _message "identifier"
@ -136,11 +144,11 @@ _whois_single () {
} }
_whois_multi () { _whois_multi () {
local state line expl local curcontext="$curcontext" state line expl
typeset -A opt_args typeset -A opt_args
local tmp host local tmp host
_arguments \ _arguments -C \
"$_whois_arguments[@]" \ "$_whois_arguments[@]" \
'*::identifier:->identifier' '*::identifier:->identifier'
@ -153,7 +161,7 @@ _whois_multi () {
break break
fi fi
done done
if builtin functions "_whois:$host" >&-; then if (( $+functions[_whois:$host] )); then
"_whois:$host" "$expl[@]" "_whois:$host" "$expl[@]"
else else
_message "identifier" _message "identifier"
@ -166,13 +174,13 @@ _whois_fwhois () {
if compset -P '*@'; then if compset -P '*@'; then
_whois_hosts "$@" _whois_hosts "$@"
else else
if [[ -z "$QIPREFIX" ]]; then if [[ -z "$QIPREFIX" && -z "$PREFIX" ]]; then
compadd -QS '' \' compadd -QS '' \'
return return
fi fi
compset -q compset -q
host="$_whois_defaultserver" host="$_whois_defaultserver"
if builtin functions "_whois:$host" >&-; then if (( $+functions[_whois:$host] )); then
"_whois:$host" "$@" "_whois:$host" "$@"
else else
_message "identifier" _message "identifier"
@ -181,28 +189,33 @@ _whois_fwhois () {
} }
_whois_hosts () { _whois_hosts () {
compadd "$@" \ _tags hosts &&
-M 'm:{a-zA-Z}={A-Za-z} r:|.=* r:|=*' \ compadd "$@" \
- ${_whois_servers%:?} || _hosts "$@" -M 'm:{a-zA-Z}={A-Za-z} r:|.=* r:|=*' \
- ${_whois_servers%:?} || _hosts "$@"
} }
_whois_ports () { _whois_ports () {
compadd "$@" - whois || _ports "$@" _tags ports && compadd "$@" - whois || _ports "$@"
} }
builtin functions _whois:whois.internic.net >&- || (( $+functions[_whois:whois.internic.net] )) ||
_whois:whois.internic.net () { _whois:whois.internic.net () {
if (( CURRENT == 1 )); then if (( CURRENT == 1 )); then
compadd HELP DOMAIN HOST local expl
_wanted strings expl string compadd HELP DOMAIN HOST
else else
_message 'string' _message 'string'
fi fi
} }
builtin functions _whois:whois.nic.ad.jp >&- || (( $+functions[_whois:whois.nic.ad.jp] )) ||
_whois:whois.nic.ad.jp () { _whois:whois.nic.ad.jp () {
if (( CURRENT == 1 )); then if (( CURRENT == 1 )); then
compadd HELP DOM NET HOST PERSON CONN COM local expl
_wanted strings expl string compadd HELP DOM NET HOST PERSON CONN COM
else else
_message 'string' _message 'string'
fi fi

View file

@ -2,7 +2,7 @@
local expl list desc local expl list desc
_wanted colormapids || return 1 _tags colormapids || return 1
list=(${(f)"$(xprop -root -f RGB_COLOR_MAP 32xcccccccxx ': $0\n'|awk -F'[ ():]' '/^[a-zA-Z_]+\(RGB_COLOR_MAP\)/ {print $5, "--", $1}')"}) list=(${(f)"$(xprop -root -f RGB_COLOR_MAP 32xcccccccxx ': $0\n'|awk -F'[ ():]' '/^[a-zA-Z_]+\(RGB_COLOR_MAP\)/ {print $5, "--", $1}')"})
@ -12,5 +12,5 @@ else
desc=() desc=()
fi fi
_all_labels colormapids expl 'colormap id' \ _wanted colormapids expl 'colormap id' \
compadd "$@" "$desc[@]" - "${(@)list%% *}" compadd "$@" "$desc[@]" - "${(@)list%% *}"

View file

@ -1,3 +1,3 @@
#autoload #autoload
_wanted displays && _hosts -S ':0 ' -r : _tags displays && _hosts -S ':0 ' -r :

View file

@ -2,18 +2,18 @@
local expl local expl
_wanted extensions || return 1 _tags extensions || return 1
(( $+_xe_cache )) || _xe_cache=( "${(@)${(@f)$(xdpyinfo)}[(r)number of extensions:*,-1][2,(r)default screen number:*][1,-2]//[ ]}" ) (( $+_xe_cache )) || _xe_cache=( "${(@)${(@f)$(xdpyinfo)}[(r)number of extensions:*,-1][2,(r)default screen number:*][1,-2]//[ ]}" )
if [[ "$1" = -a ]]; then if [[ "$1" = -a ]]; then
shift shift
_all_labels extensions expl 'X extensions' \ _wanted extensions expl 'X extensions' \
compadd "$@" -M 'm:{a-z}={A-Z} r:|-=* r:|=*' - all "$_xe_cache[@]" compadd "$@" -M 'm:{a-z}={A-Z} r:|-=* r:|=*' - all "$_xe_cache[@]"
else else
[[ "$1" = - ]] && shift [[ "$1" = - ]] && shift
_all_labels extensions expl 'X extensions' \ _wanted extensions expl 'X extensions' \
compadd "$@" -M 'm:{a-z}={A-Z} r:|-=* r:|=*' - "$_xe_cache[@]" compadd "$@" -M 'm:{a-z}={A-Z} r:|-=* r:|=*' - "$_xe_cache[@]"
fi fi

View file

@ -2,7 +2,7 @@
local expl local expl
_wanted fonts || return 1 _tags fonts || return 1
# This *has* to be improved some day... # This *has* to be improved some day...
@ -12,5 +12,5 @@ if (( ! $+_font_cache )); then
_font_cache=( "${(@)^${(@f)$(_call fonts xlsfonts)}%%--*}--" ) _font_cache=( "${(@)^${(@f)$(_call fonts xlsfonts)}%%--*}--" )
fi fi
_all_labels fonts expl font \ _wanted fonts expl font \
compadd -M 'r:|-=* r:|=*' "$@" -S '' - "$_font_cache[@]" compadd -M 'r:|-=* r:|=*' "$@" -S '' - "$_font_cache[@]"

View file

@ -2,7 +2,7 @@
local expl local expl
_wanted keysyms || return 1 _tags keysyms || return 1
if (( ! $+_keysym_cache )); then if (( ! $+_keysym_cache )); then
local file local file
@ -18,5 +18,5 @@ if (( ! $+_keysym_cache )); then
fi fi
fi fi
_all_labels keysyms expl 'key symbol' \ _wanted keysyms expl 'key symbol' \
compadd "$@" -M 'm:{a-z}={A-Z} r:|-=* r:|=*' - $_keysym_cache compadd "$@" -M 'm:{a-z}={A-Z} r:|-=* r:|=*' - $_keysym_cache

View file

@ -2,17 +2,17 @@
local list expl local list expl
_wanted windows || return 1 _tags windows || return 1
list=( "${(@)${(M@)${(@f)$(_call windows xwininfo -root -tree)}:#[ ]#0x[0-9a-f]# \"*}##[ ]#}" ) list=( "${(@)${(M@)${(@f)$(_call windows xwininfo -root -tree)}:#[ ]#0x[0-9a-f]# \"*}##[ ]#}" )
if [[ "$1" = -n ]]; then if [[ "$1" = -n ]]; then
shift shift
_all_labels windows expl 'window name' \ _wanted windows expl 'window name' \
compadd "$@" -d list - "${(@)${(@)list#*\"}%%\"*}" compadd "$@" -d list - "${(@)${(@)list#*\"}%%\"*}"
else else
[[ "$1" = - ]] && shift [[ "$1" = - ]] && shift
_all_labels windows expl 'window ID' compadd "$@" -d list - "${(@)list%% *}" _wanted windows expl 'window ID' compadd "$@" -d list - "${(@)list%% *}"
fi fi

View file

@ -82,12 +82,14 @@ if [[ -n "$state" ]]; then
[[ "$what" = *ksym* ]] && _x_keysym "$suf[@]" && ret=0 [[ "$what" = *ksym* ]] && _x_keysym "$suf[@]" && ret=0
else else
if _wanted commands; then _tags commands
while _tags; do
while _next_label commands expl command; do while _next_label commands expl command; do
compadd "$expl[@]" -S ' ' keycode keysym clear add remove && ret=0 compadd "$expl[@]" -S ' ' keycode keysym clear add remove && ret=0
compadd "$expl[@]" -S ' = ' pointer && ret=0 compadd "$expl[@]" -S ' = ' pointer && ret=0
done done
fi (( ret )) || return 0
done
fi fi
fi fi

View file

@ -55,23 +55,29 @@ xhost)
if [[ "$tmp" = *:* ]]; then if [[ "$tmp" = *:* ]]; then
if compset -P '(#b)(*):'; then if compset -P '(#b)(*):'; then
type="$match[1]" type="$match[1]"
_wanted displays && _tags displays
while _next_label displays expl 'disallow access'; do while _tags; do
while _next_label displays expl 'disallow access'; do
{ compadd "$expl[@]" -M 'm:{a-z}={A-Z} r:|[:.]=* r:|=*' - \ { compadd "$expl[@]" -M 'm:{a-z}={A-Z} r:|[:.]=* r:|=*' - \
${${(M)tmp:#(#i)$type:*}#(#i)$type:} || ${${(M)tmp:#(#i)$type:*}#(#i)$type:} ||
_hosts "$expl[@]" } && return 0 _hosts "$expl[@]" } && ret=0
done done
(( ret )) || return 0
done
else else
_alternative \ _alternative \
'types:name family:compadd -S: ${(L)tmp%%:*}' \ 'types:name family:compadd -S: ${(L)tmp%%:*}' \
'hosts:host:compadd ${(@)tmp#*:}' && ret=0 'hosts:host:compadd ${(@)tmp#*:}' && ret=0
fi fi
else else
_wanted displays && _tags displays
while _next_label displays expl 'disallow access'; do while _tags; do
{ compadd "$expl[@]" -M 'm:{a-z}={A-Z} r:|[:.]=* r:|=*' - $tmp || while _next_label displays expl 'disallow access'; do
_hosts "$expl[@]" } && return 0 { compadd "$expl[@]" -M 'm:{a-z}={A-Z} r:|[:.]=* r:|=*' - $tmp ||
done _hosts "$expl[@]" } && ret=0
done
(( ret )) || return 0
done
fi fi
else else
compset -P + compset -P +

View file

@ -17,7 +17,7 @@ _xwit_guard () {
_xwit_compopts () { _xwit_compopts () {
local expl local expl
_wanted options expl option compadd - ${(k)no[(R)*~0]} || _wanted options expl option compadd - ${(k)no[(R)*~0]} ||
_all_labels options expl option compadd - ${(k)no} _wanted options expl option compadd - ${(k)no}
} }
_regex_arguments _xwit_parse \ _regex_arguments _xwit_parse \

View file

@ -945,15 +945,19 @@ expected by the caller of tt(_files).
If the tt(file-patterns) style is set, the default tags are not If the tt(file-patterns) style is set, the default tags are not
used. Instead, the value of the style says which tags and which used. Instead, the value of the style says which tags and which
patterns are to be offered. The strings in the value are of the form patterns are to be offered. The strings in the value contain
`var(patterns)tt(:)var(tag)'. The var(patterns) gives one or more glob specifications of the form
patterns separated by spaces that are to be used to generate `var(patterns)tt(:)var(tag)'; each string may contain any number of
such specifications. The var(patterns) give one or more glob
patterns separated by commas that are to be used to generate
filenames. If it contains the sequence `tt(%p)', that is replaced by filenames. If it contains the sequence `tt(%p)', that is replaced by
the pattern(s) given by the calling function. the pattern(s) given by the calling function.
Colons in the pattern have to be preceded by a backslash to Colons in the pattern have to be preceded by a backslash to
make them distinguishable from the colon before the var(tag). The make them distinguishable from the colon before the var(tag). The
var(tag)s of all strings in the value will be offered by tt(_files) var(tag)s of all strings in the value will be offered by tt(_files)
(again, one after another) and used when looking up other styles. If (again, one after another) and used when looking up other styles. For
strings containing more than one specification, the filenames for all
specifications will be generated at the same try. If
no `tt(:)var(tag)' is given the `tt(files)' tag will be used. The no `tt(:)var(tag)' is given the `tt(files)' tag will be used. The
var(tag) may also be var(tag) may also be
followed by an optional second colon and a description. If that is followed by an optional second colon and a description. If that is
@ -978,7 +982,7 @@ directories in the first try and all files as the second try. To
achieve this, one could do: achieve this, one could do:
example(zstyle ':completion:*' file-patterns \ example(zstyle ':completion:*' file-patterns \
'%p *(-/):globbed-files' '*:all-files') '%p:globbed-files *(-/):directories' '*:all-files')
Note also that during the execution of completion functions, the Note also that during the execution of completion functions, the
tt(EXTENDED_GLOB) option is in effect, so the characters `tt(#)', tt(EXTENDED_GLOB) option is in effect, so the characters `tt(#)',
@ -2216,22 +2220,12 @@ var(N), complete the var(N)th most recently modified file. Note the
completion, if any, is always unique. completion, if any, is always unique.
) )
findex(_next_tags) findex(_next_tags)
item(tt(_next_tags))( item(tt(_next_tags) (^Xn))(
This allows to complete types of matches that are not immediately This allows to complete types of matches that are not immediately
offered because of the setting of the tt(tag-order) style. After a offered because of the setting of the tt(tag-order) style. After a
normal completion was tried, invoking this command makes the matches normal completion was tried, invoking this command makes the matches
for the next tag (or set of tags) be used. Repeatedly invoking this for the next tag (or set of tags) be used. Repeatedly invoking this
command makes the following tags be used. To be able to complete the command makes the following tags be used.
matches selected by tt(_next_tags), the tt(completer) style should
contain tt(_next_tags) as its first string. With that, the normal key
binding (normally tt(TAB)) can be used to complete the matches shown
after the call to tt(_next_tags).
Normally, this command is not bound to a key. To invoke it with, say
`tt(^Xn)', one would use:
example(zle -C _next_tags complete-word _next_tags
bindkey '^Xn' _next_tags)
) )
findex(_read_comp (^X^R)) findex(_read_comp (^X^R))
item(tt(_read_comp (^X^R)))( item(tt(_read_comp (^X^R)))(
@ -2442,7 +2436,7 @@ user to the tt(tag-order) style is prefered over the one given to
tt(_next_label). tt(_next_label).
Note that this function must not be called without a previous call to Note that this function must not be called without a previous call to
tt(_tags), tt(_wanted) or tt(_requested) because it uses the tag label tt(_tags) or tt(_requested) because it uses the tag label
for the current tag found by these functions. for the current tag found by these functions.
A normal use of this function for the tag labels for the tag tt(foo) A normal use of this function for the tag labels for the tag tt(foo)
@ -2450,12 +2444,13 @@ looks like this:
example(local expl ret=1 example(local expl ret=1
... ...
_wanted foo || return 1 if _requested foo; then
... ...
while _next_label foo expl '...'; do while _next_label foo expl '...'; do
compadd "$expl[@]" ... && ret=0 compadd "$expl[@]" ... && ret=0
done done
... ...
fi
return ret return ret
) )
) )
@ -2477,9 +2472,10 @@ For example:
example(local expl example(local expl
... ...
_wanted foo || return 1 if _requested foo; then
... ...
_all_labels foo expl '...' compadd ... - $matches) _all_labels foo expl '...' compadd ... - $matches
fi)
Will complete the strings from the tt(matches) parameter, using Will complete the strings from the tt(matches) parameter, using
tt(compadd) with additional options which will take precedence over tt(compadd) with additional options which will take precedence over
@ -2525,7 +2521,7 @@ while _tags; do
done) done)
) )
findex(_wanted) findex(_wanted)
item(tt(_wanted) [ tt(-12VJ) ] var(tag) var(name) var(descr) [ var(specs) ... ])( item(tt(_wanted) [ tt(-12VJ) ] var(tag) var(name) var(descr) var(command) var(args) ...)(
In many contexts only one type of matches can be generated but even In many contexts only one type of matches can be generated but even
then it should be tested if the tag representing those matches is then it should be tested if the tag representing those matches is
requested by the user. This function makes that easier. requested by the user. This function makes that easier.
@ -2538,6 +2534,10 @@ description built, you can just do:
example(_wanted tag expl 'description' \ example(_wanted tag expl 'description' \
compadd matches...) compadd matches...)
Unlike tt(_requested), however, tt(_wanted) can not be called without
the var(command). That's because tt(_wanted) also implements the loop
over the tags, not only the one for the labels.
) )
findex(_alternative) findex(_alternative)
item(tt(_alternative) [ tt(-C) var(name) ] var(specs) ...)( item(tt(_alternative) [ tt(-C) var(name) ] var(specs) ...)(

View file

@ -63,12 +63,12 @@ example).
Then, before adding the matches, see if matches of that type are Then, before adding the matches, see if matches of that type are
requested by the user in the current context. If you will add only one requested by the user in the current context. If you will add only one
type of matches, this is very simple. You can use the function type of matches, this is very simple. You can use the function
`_wanted' for this. Its return value is zero only if the type of `_wanted' for this. Well, you can often use it, that is. Use it as in:
matches is requested by the user, so you can just do:
_wanted names || return 1 _wanted names expl 'name' compadd - alice bob
_all_labels names expl 'name' compadd - alice bob This is like testing if the tag `names' is requested by the user and
then calling `_all_labels' with the same arguments.
The `_all_labels' function implements the loop over the tag aliases and The `_all_labels' function implements the loop over the tag aliases and
handles the user-defined description, using (in the example) the handles the user-defined description, using (in the example) the
@ -88,13 +88,6 @@ the last argument. A good example for such a function is
And the `-' will be replaced by the options that are to be given to And the `-' will be replaced by the options that are to be given to
`compadd'. `compadd'.
Since the above sequence of command is used so often, the `_wanted'
function can also accept the same arguments as `_all_labels'. In this
case it will do the test for the requested tag and then just call
`_all_labels', so:
_wanted names expl 'name' compadd - alice bob
Note that you can also give the `-J' and `-V' options with the Note that you can also give the `-J' and `-V' options with the
optional `1' or `2' preceding them supported by `_description': optional `1' or `2' preceding them supported by `_description':
@ -332,11 +325,11 @@ often be using the tags function that allows you to give the
explanation to the same function that is used to test if the tags are explanation to the same function that is used to test if the tags are
requested (again: see above). Just as a reminder: requested (again: see above). Just as a reminder:
_wanted [ -[1,2]V | -[1,2]J ] <tag> expl <descr> _wanted [ -[1,2]V | -[1,2]J ] <tag> expl <descr> <cmd> ...
and and
_requested [ -[1,2]V | -[1,2]J ] <tag> expl <descr> _requested [ -[1,2]V | -[1,2]J ] <tag> expl <descr> [ <cmd> ... ]
is all you need to make your function work correctly with both tags is all you need to make your function work correctly with both tags
and description at the same time. and description at the same time.

View file

@ -30,7 +30,7 @@ if [[ $ZFTP_SYSTEM = UNIX* ]]; then
rm -f $tmpf rm -f $tmpf
[[ -n $dir && $dir != */ ]] && dir="$dir/" [[ -n $dir && $dir != */ ]] && dir="$dir/"
if [[ -n $WIDGET ]]; then if [[ -n $WIDGET ]]; then
_all_labels directories expl 'remote directory' _wanted directories expl 'remote directory'
compadd -S/ -q -P "$dir" - $reply compadd -S/ -q -P "$dir" - $reply
elif [[ -n $dir ]]; then elif [[ -n $dir ]]; then
reply=(${dir}$reply) reply=(${dir}$reply)

View file

@ -17,7 +17,7 @@ if [[ $ZFTP_SYSTEM == UNIX* && $1 == */* ]]; then
local reply local reply
reply=(${${${(f)"$(<$tmpf)"}##$dir}%\*}) reply=(${${${(f)"$(<$tmpf)"}##$dir}%\*})
rm -f $tmpf rm -f $tmpf
_all_labels files expl 'remote file' compadd -P $dir - $reply _wanted files expl 'remote file' compadd -P $dir - $reply
else else
# On the first argument to ls, we usually get away with a glob. # On the first argument to ls, we usually get away with a glob.
zftp ls "$1*$2" >$tmpf zftp ls "$1*$2" >$tmpf
@ -28,7 +28,7 @@ else
local fcache_name local fcache_name
zffcache zffcache
if [[ -n $WIDGET ]]; then if [[ -n $WIDGET ]]; then
_all_labels files expl 'remote file' compadd -F fignore - ${(P)fcache_name} _wanted files expl 'remote file' compadd -F fignore - ${(P)fcache_name}
else else
reply=(${(P)fcache_name}); reply=(${(P)fcache_name});
fi fi

View file

@ -2291,7 +2291,7 @@ bin_comptags(char *nam, char **args, char *ops, int func)
case 'N': min = 0; max = 0; break; case 'N': min = 0; max = 0; break;
case 'R': min = 1; max = 1; break; case 'R': min = 1; max = 1; break;
case 'S': min = 1; max = 1; break; case 'S': min = 1; max = 1; break;
case 'A': min = 2; max = 2; break; case 'A': min = 2; max = 3; break;
default: default:
zwarnnam(nam, "invalid option: %s", args[0], 0); zwarnnam(nam, "invalid option: %s", args[0], 0);
return 1; return 1;
@ -2365,6 +2365,14 @@ bin_comptags(char *nam, char **args, char *ops, int func)
} }
s->ptr = q + 1; s->ptr = q + 1;
setsparam(args[2], ztrdup(*v == '-' ? dyncat(args[1], v) : v)); setsparam(args[2], ztrdup(*v == '-' ? dyncat(args[1], v) : v));
if (args[3]) {
char *r = dupstring(*q), *p;
for (p = r + (v - *q); *p && *p != ':'; p++);
*p = '\0';
setsparam(args[3], ztrdup(r));
}
return 0; return 0;
} }
return 1; return 1;