diff options
Diffstat (limited to 'Completion/Zsh')
27 files changed, 258 insertions, 93 deletions
diff --git a/Completion/Zsh/Command/_bindkey b/Completion/Zsh/Command/_bindkey index 4c4aeda9d..81ae69974 100644 --- a/Completion/Zsh/Command/_bindkey +++ b/Completion/Zsh/Command/_bindkey @@ -27,14 +27,11 @@ _arguments -C -s -S \ '(-l -L -d -D -A -N -m -p -r *)-s[bind each in-string to each out-string]:*:key string' \ '(-e -v -a -M -l -L -d -D -A -N -m -p)-R[interpret in-strings as ranges]' \ '(-l -L -d -A -N -m -p -r -s):in-string' \ - '(-l -L -d -A -N -m -p -r -s)*::widgets:->widget' && ret=0 + '(-l -L -d -A -N -m -p -r -s)*::widgets:_widgets' && ret=0 case $state in keymap) - _wanted -C -M keymaps expl keymap compadd -a keymaps && ret=0 - ;; - widget) - _wanted widgets expl widget compadd -M 'r:|-=* r:|=*' -k widgets && ret=0 + _wanted keymaps expl keymap compadd -a keymaps && ret=0 ;; esac diff --git a/Completion/Zsh/Command/_fc b/Completion/Zsh/Command/_fc index 68456cc3d..dd014e7d7 100644 --- a/Completion/Zsh/Command/_fc +++ b/Completion/Zsh/Command/_fc @@ -1,7 +1,8 @@ #compdef fc history r -local curcontext="$curcontext" state state_descr line ret=1 -local events num cmd sep +local curcontext="$curcontext" state state_descr line expl ret=1 +local num cmd sep +local -a events typeset -A opt_args local fc_common fc_hist fc_r @@ -68,10 +69,10 @@ 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[@]}")"} ) + print -v events -f "%-${#HISTNO}.${#HISTNO}s $sep %s" "${(kv)history[@]}" _wanted -2V events expl "$state_descr" compadd -M "B:0=" -ld events - \ "${events[@]%% *}" elif [[ -prefix - ]]; then diff --git a/Completion/Zsh/Command/_precommand b/Completion/Zsh/Command/_precommand index f848721d9..f57e668c6 100644 --- a/Completion/Zsh/Command/_precommand +++ b/Completion/Zsh/Command/_precommand @@ -1,4 +1,4 @@ -#compdef - nohup eval time rusage noglob nocorrect exec catchsegv aoss hilite eatmydata +#compdef - nohup eval time rusage noglob nocorrect exec catchsegv aoss hilite eatmydata setsid # precommands is made local in _main_complete precommands+=($words[1]) diff --git a/Completion/Zsh/Command/_print b/Completion/Zsh/Command/_print index 1eba13e88..0610cd4cf 100644 --- a/Completion/Zsh/Command/_print +++ b/Completion/Zsh/Command/_print @@ -1,15 +1,18 @@ #compdef print printf -local state expl line eflag pflag rest ret=1 +local state expl line eflag pflag rflag rest ret=1 if [[ $service = print ]]; then # -e flag available only after -R eflag="${words[1,CURRENT-1][(r)-*R*]:+-e[enable escapes]}" + rflag='-r[ignore escape conventions of echo]' # -p flag only relevant if we have a coprocess (:>&p) 2>/dev/null && pflag='(-s -u -z)-p[print arguments to input of coprocess]' + [[ -n ${words[(r)-*f]} ]] && rflag='-r[disable reuse of format string]' + if [[ -n ${words[1,CURRENT][(r)-*P*]} ]]; then rest='*: :->prompt' else @@ -17,32 +20,37 @@ if [[ $service = print ]]; then fi _arguments -C -s -A "-*" -S \ - '(-f)-r[ignore escape conventions of echo]' \ - '(-r -b -f -m -s -l -N -o -O -i -c -u -p -z -D -P)-R[emulate BSD echo (no escapes, -n & -e flags only)]' \ + '-r[ignore escape conventions of echo]' \ + '(-r -b -f -m -s -S -l -N -o -O -i -c -u -p -z -D -P)-R[emulate BSD echo (no escapes, -n & -e flags only)]' \ '-b[recognise bindkey escape sequences]' \ - '-m[remove arguments matching specified pattern]' \ - '(-r -n -R -l -N -c)-f+[print arguments as for the printf builtin]:format:->printfformat' \ - '(-u -p -z)-s[place results in the history list]' \ + '-m[remove arguments not matching specified pattern]:pattern' \ + '(-n -R -l -N -c -S)-f+[print arguments as for the printf builtin]:format:->printfformat' \ + '(-u -p -z -S)-s[place results in the history list]' \ + '(-a -f -c -C -i -l -o -O -N -u -p -v -z -s -x -X)-S[place results in the history list, after splitting argument into words]' \ '(-c -f)-n[do not add a newline to the result]' \ - '(-N -c -f)-l[print arguments separated by newlines]' \ - '(-n -l -c -f)-N[print arguments separated and terminated by nulls]' \ - '(-O)-o[sort arguments in ascending order]' \ - '(-o)-O[sort arguments in descending order]' \ - '-i[case-insensitive sorting]' \ - '(-n -l -N -f -s -z)-a[with -c/-C, print arguments across before down]' \ - '(-n -l -N -f -C -s -z)-c[print arguments in columns]' \ - '(-n -l -N -f -c -s -z)-C+[print arguments in specified number of columns]:columns' \ - '(-s -p -z)-u+[specify file descriptor to print arguments to]:file descriptor:_file_descriptors' \ - '(-s -p -u)-z[push arguments onto editing buffer stack]' \ + '(-N -c -f -S)-l[print arguments separated by newlines]' \ + '(-n -l -c -f -S)-N[print arguments separated and terminated by nulls]' \ + '(-O -S)-o[sort arguments in ascending order]' \ + '(-o -S)-O[sort arguments in descending order]' \ + '(-S)-i[case-insensitive sorting]' \ + '(-n -l -N -f -s -S -z)-a[with -c/-C, print arguments across before down]' \ + '(-n -l -N -f -C -s -S -z)-c[print arguments in columns]' \ + '(-n -l -N -f -c -s -S -z)-C+[print arguments in specified number of columns]:columns' \ + '(-s -S -p -z)-u+[specify file descriptor to print arguments to]:file descriptor:_file_descriptors' \ + '(-s -S -z -p -u)-v[store output in named parameter]:parameter:_parameters' \ + '(-s -S -p -u)-z[push arguments onto editing buffer stack]' \ '-D[substitute any arguments which are named directories using ~ notation]' \ '-P[perform prompt expansion]' \ - $pflag $eflag $rest && ret=0 + '(-X -f -a -C -c -s -S -z)-x+[expand leading tabs]:tab width' \ + '(-x -f -a -C -c -s -S -z)-X+[expand all tabs]:tab width' \ + $pflag $eflag $rflag $rest && ret=0 elif [[ $service = printf ]]; then state=printf fi if [[ $state = printf ]]; then _arguments -C -s -S \ + '-v[store output in named parameter]:parameter:_parameters' \ '1:format:->printfformat' \ '*: :_default' && ret=0 fi diff --git a/Completion/Zsh/Command/_strftime b/Completion/Zsh/Command/_strftime index 0be7b078d..24ff7dc3e 100644 --- a/Completion/Zsh/Command/_strftime +++ b/Completion/Zsh/Command/_strftime @@ -6,7 +6,7 @@ _arguments -S -A '-*' -s \ '-q[run quietly]' \ '-r[reverse lookup using strptime]' \ '-s+[assign result to parameter]:param:_parameters' \ - '1:format: _date_formats' \ + '1:format: _date_formats zsh' \ '2:epoch time (or date string with -r)' && ret=0 return ret diff --git a/Completion/Zsh/Command/_typeset b/Completion/Zsh/Command/_typeset index 4e29c23e7..160150234 100644 --- a/Completion/Zsh/Command/_typeset +++ b/Completion/Zsh/Command/_typeset @@ -21,6 +21,7 @@ allargs=( X '+X[immediately autoload function]' Z "($fopts -A -E -F -i)-Z+[right justify and fill with leading zeros]:width" a "($fopts -A -E -F -T -i)-a[specify that arguments refer to arrays]" + df "-d[default absolute path autoload to fpath]" f "($popts)-f[specify that arguments refer to functions]" g "($fopts -T)-+g[do not restrict parameter to local scope]" h "($fopts -T)-+h[hide specialness of parameter]" @@ -31,6 +32,8 @@ allargs=( m '(-A -E -F -T -i)-m[treat arguments as patterns]' p '-p[output parameters in form of calls to typeset]' r '(-f)-+r[mark parameters as readonly]' + rf '-r[remember autoload path]' + Rf '-R[remember autoload path, error if not found]' t '(-T)-+t[tag parameters and turn on execution tracing for functions]' tf '(-T)-+t[turn on execution tracing for functions]' tp '(-T)-+t[tag parameters]' @@ -46,7 +49,7 @@ use="AEFHLRTUZafghiklmprtuxz" case ${service} in autoload) - use="UTXktwz" + use="URTXdkrtwz" func=f ;; float) use="EFHghlprtux";; @@ -57,7 +60,7 @@ case ${service} in ;; integer) use="Hghilprtux" - allargs[i]='-i[specify arithmetic base for output]' \ + allargs[i]='-i+[specify arithmetic base for output]:: :_guard "[0-9]#" base' \ ;; readonly) use="${use/r/}" ;; local) use="${use/[fkz]/}" ;& @@ -74,7 +77,7 @@ onopts=${(j..)${${words[1,CURRENT-1]:#^-*}##-}} offopts=${(j..)${${words[1,CURRENT-1]:#^+*}##+}} for ((i=1;i<=$#use;++i)); do - args+=( ${allargs[${use[$i]}${${(s::)use[$i]}[(r)[UutT]]:+$func}]} ) + args+=( ${allargs[${use[$i]}${${(s::)use[$i]}[(r)[dUurRtT]]:+$func}]} ) done _arguments -C -s -A "-*" -S "${args[@]}" '*::vars:= ->vars_eq' @@ -90,12 +93,17 @@ if [[ "$state" = vars_eq ]]; then elif (( $+opt_args[-w] )); then _wanted files expl 'zwc file' _files -g '*.zwc(-.)' elif [[ $service = autoload || -n $opt_args[(i)-[uU]] ]]; then - args=(${^fpath}/*(-.:t)) - # Filter out functions already loaded or marked for autoload. - local -a funckeys - funckeys=(${(k)functions}) - args=(${args:|funckeys}) - _wanted functions expl 'shell function' compadd -a args + if [[ $PREFIX[1] = [/~] ]]; then + # Autoload by absolute path + _files + else + args=(${^fpath}/*(-.:t)) + # Filter out functions already loaded or marked for autoload. + local -a funckeys + funckeys=(${(k)functions}) + args=(${args:|funckeys}) + _wanted functions expl 'shell function' compadd -a args + fi elif [[ -n $onopts$offopts ]]; then if [[ -n $offopts ]]; then args=(${(f)"$(functions +${offopts//[^UXkmtTuz]/})"}) diff --git a/Completion/Zsh/Command/_vared b/Completion/Zsh/Command/_vared index bb31cc129..aba64880a 100644 --- a/Completion/Zsh/Command/_vared +++ b/Completion/Zsh/Command/_vared @@ -6,6 +6,8 @@ _arguments -s -A "-*" \ "-c[create parameter or change type]" \ '-p+[specify left prompt]:prompt' \ '-r+[specify right prompt]:right prompt' \ + '-i+[specify initialisation widget]:widget:_widgets' \ + '-f+[specify finish widget]:widget:_widgets' \ '-h[allow access to history]' \ '-e[exit on EOF (^D)]' \ '1:parameter spec:_vars' diff --git a/Completion/Zsh/Command/_zed b/Completion/Zsh/Command/_zed index 184234b02..211dae7df 100644 --- a/Completion/Zsh/Command/_zed +++ b/Completion/Zsh/Command/_zed @@ -1,7 +1,9 @@ #compdef zed fned case $service in -(fned) _arguments ':shell function:_functions';; -(zed) _arguments '(-):file:_files' \ - '(:)-f[edit function]:shell function:_functions';; +(fned) _arguments -S : ':shell function:_functions';; +(zed) _arguments -S : \ + '(- 2):file:_files' \ + '(1):shell function:_functions' \ + '(1)-f[edit function]';; esac diff --git a/Completion/Zsh/Command/_zle b/Completion/Zsh/Command/_zle index 3ed373348..e01d0a943 100644 --- a/Completion/Zsh/Command/_zle +++ b/Completion/Zsh/Command/_zle @@ -45,23 +45,25 @@ case "$state[1]" in _arguments \ '(-N)-n[numeric prefix]:number:' \ '(-n)-N[reset numeric prefix]' \ + '-K[specify temporary keymap]:keymap:compadd -a keymaps' \ + '-w[set $WIDGET to reflect widget being called]' \ '(-)*:widget arguments: ' && ret=0 ;; (widget*) - _wanted -C "$context[1]" widgets expl "${state_descr[1]:-widget}" compadd -k widgets && ret=0 + _wanted -C "$context[1]" widgets expl "${state_descr[1]:-widget}" _widgets && ret=0 ;& (function) [[ $state[1] != *function ]] || # Handle fall-through _wanted -C "$context[1]" functions expl 'widget shell function' \ - compadd -k functions && ret=0 + compadd -M 'r:|-=* r:|=*' -k functions && ret=0 ;; (comp-widget) _wanted -C "$context[1]" widgets expl 'completion widget' \ - compadd -k "widgets[(R)(*:|)(.|)(${(j(|))compwids})(|:*)]" && ret=0 + _widgets -g "(*:|)(.|)(${(j(|))compwids})(|:*)" && ret=0 ;& (builtin-comp-widget) _wanted -C "$context[1]" widgets expl 'builtin completion widget' \ - compadd -k "widgets[(I)(.|)(${(j(|))compwids})]" && ret=0 + compadd -M 'r:|-=* r:|=*' -k "widgets[(I)(.|)(${(j(|))compwids})]" && ret=0 ;; (redisplay) _arguments -s -S '!-R' \ diff --git a/Completion/Zsh/Command/_zstyle b/Completion/Zsh/Command/_zstyle index 9a6d61891..0e828225e 100644 --- a/Completion/Zsh/Command/_zstyle +++ b/Completion/Zsh/Command/_zstyle @@ -1,25 +1,9 @@ #compdef zstyle local state context ostate line expl ctop suf -local nm=$compstate[nmatches] taglist patterns pstyles contexts +local nm=$compstate[nmatches] taglist patterns contexts typeset -A opt_args styles -(( $+functions[_completers] )) || -_completers() { - # option: -p - needs a `_' prefix - local us - local -a disp list expl - - list=( complete approximate correct match expand list menu oldlist - ignored prefix history ) - zparseopts -D -K -E 'p=us' - [[ -n "$us" ]] && us='_' - zstyle -t ":completion:${curcontext}:completers" prefix-hidden && - disp=(-d list) - _wanted completers expl 'completer' \ - compadd "$@" "$disp[@]" - "$us${^list[@]}" -} - _vcs_info_hooks() { compadd - ${functions[(I)+vi-*]#+vi-} } @@ -173,6 +157,7 @@ styles=( url-seps e: whence e: word-chars e: + word-class e: word-style e:word-style word-context e: @@ -231,21 +216,33 @@ taglist=( email-address ${(k)functions[(I)_email-*]#_} ) +# Be careful with the context arguments here. They like to masquerade. _arguments -C \ - '(-)-L[output in form of zstyle commands]' \ - '(: -)-d[delete style definitions]:context pattern:->patterns:*:styles:->pstyles' \ - '(-)-e[value is evaluated when style is looked up]' \ - ':context:->contexts' ':style:->styles' '*:argument:->style-arg' + '(: -)-L[output in form of zstyle commands]:pattern for context patterns:->metapatterns:style:->metastyles' \ + '(: -)-d[delete style definitions]:verbatim context pattern:->patterns:*:styles:->pstyles' \ + '(: -)-e[value is evaluated when style is looked up]:context pattern:->contexts:style:->styles:*:command:_cmdstring' \ + '(: -)-g[retrieve style definition]:array parameter:_parameters -g "*array*":verbatim context pattern:->patterns:styles:->pstyles' \ + '(: -)-s[retrieve style value as string]:context name:->contexts:style:->styles:scalar parameter:_parameters -g "*scalar*":separator: ' \ + '(: -)-b[retrieve style value as boolean]:context name:->contexts:style:->styles:scalar parameter:_parameters -g "*scalar*"' \ + '(: -)-a[retrieve style value as array]:context name:->contexts:style:->styles:array parameter:_parameters -g "*array*"' \ + '(: -)-t[test a style, returning false if it'\''s undefined]:context name:->contexts:style:->styles:*:strings to test presence of: ' \ + '(: -)-T[test a style, returning true if it'\''s undefined]:context name:->contexts:style:->styles:*:strings to test presence of: ' \ + '(: -)-m[pattern-match values of a style]:context name:->contexts:style:->styles:pattern: ' \ + '(-):context pattern:->contexts' '(-):style:->styles' '(-)*:argument:->style-arg' while (( $#state )); do case "$state[1]" in + # 'contexts' completes either full context names (for -t/-s/-a), or context + # patterns (for 'zstyle :foo bar' and -e). (contexts) if [[ ! -prefix :*: ]]; then - _wanted contexts expl context compadd -P : -qS : completion vcs_info zftp + _wanted contexts expl "$state_descr" compadd -P : -qS : chpwd completion vcs_info zftp zle elif compset -P :completion:; then contexts=( functions _completers cmdorcont argument tag ) elif compset -P :vcs_info:; then contexts=( vcs-string user-context repo-root-name ) + elif compset -P :zle:; then + _wanted widgets expl widget _widgets -qS : fi if (( $#contexts )); then for ostate in $contexts; do @@ -263,19 +260,80 @@ while (( $#state )); do fi ;; + # 'patterns' completes context patterns that are set, for -d/-g. (patterns) zstyle -g patterns - _wanted contexts expl 'context pattern' compadd -a patterns + _wanted contexts expl "$state_descr" compadd -a patterns ;; + # 'metapatterns': patterns that are matched not against contexts, but + # against patterns. + (metapatterns) + zstyle -g patterns + patterns=( "${(@b)patterns}" ) + _wanted contexts expl "$state_descr" compadd -a patterns + ;; + + # 'metastyles': styles that are set on context patterns matching the given + # metapattern. + (metastyles) + # Anonymous function to shadow the global $styles assoc + () { + local metapattern=${(Q)${${opt_args[-L]%:*}//(#m)\\([\\:])/${MATCH[2]}}} + local -a metastyles styles + local pattern + zstyle -g patterns + for pattern in "${(@M)patterns:#${~metapattern}}"; do + zstyle -g styles $pattern + metastyles+=( "${styles[@]}" ) + done + _wanted styles expl "$state_descr" compadd -a metastyles + unset pattern + unset metastyles + } + ;; + + # 'pstyles': complete styles that are set for the verbatim context pattern + # specified on the command line. (If the user has set no zstyles, this + # will complete nothing.) (pstyles) - zstyle -g pstyles ${(Q)${(M)opt_args[-d]#*[^\\]:}%:} + local -a pstyles + local pattern + if (( $+opt_args[-d] )); then + pattern=${opt_args[-d]} + pattern=${pattern%":${(b)PREFIX}"} # remove style + pattern=${pattern//(#m)\\([\\:])/${MATCH[2]}} # undo _arguments escaping + pattern=${(Q)pattern} # undo command-line escaping (assumes no noglob) + zstyle -g pstyles $pattern + elif (( $+opt_args[-g] )); then + pattern=${opt_args[-g]} + pattern=${pattern%":${(b)PREFIX}"} # remove style + pattern=${pattern#*:} # remove array name + pattern=${pattern//(#m)\\([\\:])/${MATCH[2]}} # undo _arguments escaping + pattern=${(Q)pattern} # undo command-line escaping (assumes no noglob) + zstyle -g pstyles $pattern + fi _wanted styles expl style compadd -a pstyles + unset pattern + unset pstyles ;; + # 'styles': complete all styles that may be set in the context given on the + # command line. This is independent of what styles are set. (styles) # Get the top-level context we're completing for, if any. - case ${(Q)line[1]} in + if [[ -n $line[1] ]]; then + # zstyle :something <TAB> + local the_context=$line[1] + else + # zstyle -x :something <TAB> + local joined_value=${(v)opt_args[(i)(-e|-s|-b|-a|-t|-T|-m)]} + local the_context=${(Q)joined_value[0, ${joined_value[(i)[^\\]:]}-2 ]} + fi + # Note: for 'zstyle :something <TAB>' and for 'zstyle -e :something <TAB>', + # $the_context is a context pattern; for -s,-b,-a,-t,-T,-m, it is a context + # name. We currently draw no distinction between these two cases. + case $the_context in (:completion:*) ctop=c ;; @@ -297,7 +355,7 @@ while (( $#state )); do ;; (*) - ctop=cdez + ctop=a-z ;; esac _wanted styles expl style \ @@ -521,7 +579,7 @@ while (( $#state )); do ;; (word-style) - _wanted word-styles expl 'word style' compadd normal shell space + _wanted word-styles expl 'word style' compadd {normal,specified,unspecified,shell,whitespace}-subword ;; (vcs-string) diff --git a/Completion/Zsh/Context/_brace_parameter b/Completion/Zsh/Context/_brace_parameter index e77d4c58b..f22db8895 100644 --- a/Completion/Zsh/Context/_brace_parameter +++ b/Completion/Zsh/Context/_brace_parameter @@ -141,7 +141,7 @@ if [[ $PREFIX = *'${('[^\)]# ]]; then flags+=( "#:evaluate as numeric expression" "@:double-quoted splitting of scalars" - "A:create array parameter" + "A:assign as an array parameter" "a:sort in array index order (with O to reverse)" "b:backslash quote pattern characters only" "c:count characters in an array (with \${(c)#...})" @@ -179,7 +179,7 @@ if [[ $PREFIX = *'${('[^\)]# ]]; then "S:search substrings in #, %, / expressions" "I:search <argument>th match in #, %, / expressions" "B:include index of beginning of match in #, %, / expressions" - "E:include index of end of match in #, %, / expressions" + "E:include index of one past end of match in #, %, / expressions" "M:include matched portion in #, %, / expressions" "N:include length of match in #, % expressions" "R:include rest (unmatched portion) in #, %, / expressions" @@ -197,6 +197,7 @@ elif compset -P '*:'; then '\:=:unconditionally assign value to parameter' '?:print error if parameter is set and non-null' '#:filter value matching pattern' + '/:replace whole word matching pattern' '|:set difference' '*:set intersection' '^:zip arrays' diff --git a/Completion/Zsh/Context/_condition b/Completion/Zsh/Context/_condition index 6f5e601f0..0285911ac 100644 --- a/Completion/Zsh/Context/_condition +++ b/Completion/Zsh/Context/_condition @@ -8,6 +8,8 @@ elif [[ "$prev" = -([a-hkprsuwxLOGSN]|[no]t|ef) ]]; then _tags -C "$prev" files && _files elif [[ "$prev" = -t ]]; then _file_descriptors +elif [[ "$prev" = -v ]]; then + _parameters -r "\= \t\n\[\-" else if [[ "$PREFIX" = -* ]] || ! zstyle -T ":completion:${curcontext}:options" prefix-needed; then @@ -30,6 +32,7 @@ else -s:non-empty\ file -t:terminal\ file\ descriptor -u:setuid\ bit + -v:set\ variable -w:writable\ file -x:executable\ file -z:empty\ string diff --git a/Completion/Zsh/Context/_subscript b/Completion/Zsh/Context/_subscript index 80642d8db..0c9a89ad5 100644 --- a/Completion/Zsh/Context/_subscript +++ b/Completion/Zsh/Context/_subscript @@ -62,6 +62,7 @@ elif compset -P '\('; then 'e[interpret * or @ as a single key]' );; (|scalar*)) flags=( + 'f[make subscripting work on lines of scalar]' 'w[make subscripting work on words of scalar]' 's[specify word separator]' 'p[recognise escape sequences in subsequent s flag]' @@ -99,10 +100,9 @@ elif [[ ${(Pt)${compstate[parameter]}} = array* ]]; then list=() for i in "$ind[@]"; do if [[ "$i" = ${PREFIX}*${SUFFIX} ]]; then - list=( "$list[@]" - "${i}:$(print -D ${(P)${compstate[parameter]}[$i]})" ) + list+=( "${i}:$(print -D -- ${(P)${compstate[parameter]}[$i]})" ) else - list=( "$list[@]" '' ) + list+=( '' ) fi done zstyle -s ":completion:${curcontext}:indexes" list-separator sep || sep=-- diff --git a/Completion/Zsh/Context/_value b/Completion/Zsh/Context/_value index 47fbc1749..22372ab36 100644 --- a/Completion/Zsh/Context/_value +++ b/Completion/Zsh/Context/_value @@ -24,6 +24,7 @@ else if [[ "$compstate[parameter]" != *-* && "$compstate[context]" = *value && "${(Pt)${compstate[parameter]}}" = assoc* ]]; then + local expl if (( CURRENT & 1 )); then _wanted association-keys expl 'association key' \ compadd -k "$compstate[parameter]" diff --git a/Completion/Zsh/Function/_add-zle-hook-widget b/Completion/Zsh/Function/_add-zle-hook-widget new file mode 100644 index 000000000..f108d1868 --- /dev/null +++ b/Completion/Zsh/Function/_add-zle-hook-widget @@ -0,0 +1,36 @@ +#compdef add-zle-hook-widget + +_add-zle-hook-widget_types() { + local -a tmp + + autoload -U add-zle-hook-widget + add-zle-hook-widget -h >&/dev/null # sets the zstyle + zstyle -g tmp zle-hook types + + compadd "$@" -M 'L:|=zle-' -M 'r:|-=* r:|=*' -- zle-${^tmp} +} + +_add-zle-hook-widget_widgets() { + local expl + if (( $+opt_args[-d] )); then + local -a tmp + zstyle -g tmp $line[1] widgets + _wanted widgets expl "installed hook" compadd -- ${tmp#<->:} && return 0 + else + _wanted widgets expl widget _widgets -g 'user:*' && return 0 + fi + return 1 +} + +_add-zle-hook-widget() { + local context state state_descr line + typeset -A opt_args + _arguments -s -w -S : \ + '(-D)-d[remove HOOK from the array]' \ + '(-d)-D[interpret HOOK as pattern to remove from the array]' \ + {-U,-z,-k}"[passed to 'autoload']" \ + ':hook type:_add-zle-hook-widget_types' \ + ':widget:_add-zle-hook-widget_widgets' +} + +_add-zle-hook-widget "$@" diff --git a/Completion/Zsh/Function/_add-zsh-hook b/Completion/Zsh/Function/_add-zsh-hook index c70a4976f..e8ae97052 100644 --- a/Completion/Zsh/Function/_add-zsh-hook +++ b/Completion/Zsh/Function/_add-zsh-hook @@ -1,9 +1,7 @@ #compdef add-zsh-hook -local context state state_descr line -typeset -A opt_args - _add-zsh-hook_hooks() { + local expl if (( $+opt_args[-d] )); then _wanted functions expl "installed hooks" compadd -a - "$line[1]_functions" && return 0 else @@ -13,6 +11,8 @@ _add-zsh-hook_hooks() { } _add-zsh-hook() { + local context state state_descr line + typeset -A opt_args _arguments -s -w -S : \ '(-D)-d[remove HOOK from the array]' \ '(-d)-D[interpret HOOK as pattern to remove from the array]' \ diff --git a/Completion/Zsh/Function/_zargs b/Completion/Zsh/Function/_zargs index c24b276f2..f974ab646 100644 --- a/Completion/Zsh/Function/_zargs +++ b/Completion/Zsh/Function/_zargs @@ -4,7 +4,7 @@ local arguments eofstr pos=$((CURRENT)) numeofs=0 ret=1 cmdpos=1 #this doesn't handle '--' on the command line, only -- #it also by extension doesn't handle eofstr being the empty string -#it also also doesn't handle eofstr being -e or --eof, and everything will +#it also doesn't handle eofstr being -e or --eof, and everything will # probably also be confused if the command at the end takes a -e, --eof= or -- eofstr=${${${${words[(r)(--eof=*|-e*)]}#--eof=}#-e}:---} while { diff --git a/Completion/Zsh/Type/_arrays b/Completion/Zsh/Type/_arrays index 24c8957e8..c28fb179e 100644 --- a/Completion/Zsh/Type/_arrays +++ b/Completion/Zsh/Type/_arrays @@ -2,4 +2,4 @@ local expl -_wanted arrays expl array _parameters "$@" - -g '*array*' +_wanted arrays expl array _parameters "$@" -g '*array*' diff --git a/Completion/Zsh/Type/_completers b/Completion/Zsh/Type/_completers new file mode 100644 index 000000000..87c986a17 --- /dev/null +++ b/Completion/Zsh/Type/_completers @@ -0,0 +1,14 @@ +#autoload + +# option: -p - needs a `_' prefix +local us +local -a disp list expl + +list=( complete approximate correct match expand list menu oldlist + ignored prefix history ) +zparseopts -D -K -E 'p=us' +[[ -n "$us" ]] && us='_' +zstyle -t ":completion:${curcontext}:completers" prefix-hidden && + disp=(-d list) +_wanted completers expl 'completer' \ + compadd "$@" "$disp[@]" - "$us${^list[@]}" diff --git a/Completion/Zsh/Type/_globflags b/Completion/Zsh/Type/_globflags index 5833dc8f1..13ef14c17 100644 --- a/Completion/Zsh/Type/_globflags +++ b/Completion/Zsh/Type/_globflags @@ -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 diff --git a/Completion/Zsh/Type/_globquals b/Completion/Zsh/Type/_globquals index 2523eb333..a904bdf0d 100644 --- a/Completion/Zsh/Type/_globquals +++ b/Completion/Zsh/Type/_globquals @@ -1,7 +1,7 @@ #autoload -local state=qual expl char delim timespec -local -a alts tdisp sdisp +local state=qual expl char delim timespec default +local -a alts tdisp sdisp tmatch smatch local -A specmap while [[ -n $PREFIX ]]; do @@ -118,14 +118,29 @@ while [[ -n $PREFIX ]]; do timespec=$PREFIX[1] if ! compset -P '[Mwhmsd]' && [[ -z $PREFIX ]]; then tdisp=( seconds minutes hours days weeks Months ) - alts+=( "time-specifiers:time specifier:compadd -E 0 -d tdisp -S '' - s m h d w M" ) + tmatch=( s m h d w M ) + if zstyle -t ":completion:${curcontext}:time-specifiers" verbose; then + zstyle -s ":completion:${curcontext}:time-specifiers" list-separator sep || sep=-- + print -v tdisp -f "%s ${sep//(#m)[%\\]/$MATCH$MATCH} %s" ${tmatch:^^tdisp} + fi + alts+=( "time-specifiers:time specifier:compadd -E 0 -d tdisp -S '' -a tmatch" ) fi if ! compset -P '[-+]' && [[ -z $PREFIX ]]; then sdisp=( before exactly since ) - alts+=("senses:sense:compadd -E 0 -d sdisp -S '' - + '' -") + smatch=( - '' + ) + if zstyle -t ":completion:${curcontext}:senses" verbose; then + zstyle -s ":completion:${curcontext}:senses" list-separator sep || sep=-- + default=" [default exactly]" + sdisp=( "- $sep before" "+ $sep since" ) + smatch=( - + ) + else + sdisp=( before exactly since ) + smatch=( - '' + ) + fi + alts+=( "senses:sense${default}:compadd -E 0 -d sdisp -S '' -a smatch" ) fi specmap=( M months w weeks h hours m minutes s seconds '(|+|-|d)' days) - alts+=('digits:digit ('${${specmap[(K)$timespec]}:-invalid time specifier}'):_dates -f ${${timespec/[-+]/d}:-d} -S ""' ) + alts+=('digits:digit ('${${specmap[(K)${timespec:-d}]}:-invalid time specifier}'):_dates -f ${${timespec/[-+]/d}:-d} -S ""' ) _alternative $alts return fi diff --git a/Completion/Zsh/Type/_history_modifiers b/Completion/Zsh/Type/_history_modifiers index 658f9f346..1a049d6cb 100644 --- a/Completion/Zsh/Type/_history_modifiers +++ b/Completion/Zsh/Type/_history_modifiers @@ -64,8 +64,8 @@ while true; do ) if (( ! global )); then list+=( - "a:absolute path" - "A:absolute path resolving symbolic links" + "a:absolute path, resolve '..' lexically" + "A:as ':a', then resolve symlinks" "c:PATH search for command" "g:globally apply s or &" "h:head - strip trailing path element" @@ -73,6 +73,7 @@ while true; do "r:root - strip suffix" "e:leave only extension" "Q:strip quotes" + "P:realpath, resolve '..' physically" "l:lower case all words" "u:upper case all words" ) diff --git a/Completion/Zsh/Type/_module_math_func b/Completion/Zsh/Type/_module_math_func index 4df8d9714..6be9c006a 100644 --- a/Completion/Zsh/Type/_module_math_func +++ b/Completion/Zsh/Type/_module_math_func @@ -6,4 +6,4 @@ local -a funcs funcs=(${${${(f)"$(zmodload -Fl zsh/mathfunc 2>/dev/null)"}:#^+f:*}##+f:}) _wanted module-math-functions expl 'math function from zsh/mathfunc' \ - compadd -S '(' "$@" -a funcs + compadd -S '(' -q "$@" -a funcs diff --git a/Completion/Zsh/Type/_ps1234 b/Completion/Zsh/Type/_ps1234 index 8edf0d0cb..cf1982219 100644 --- a/Completion/Zsh/Type/_ps1234 +++ b/Completion/Zsh/Type/_ps1234 @@ -1,6 +1,6 @@ #compdef -value-,PROMPT,-default- -value-,PROMPT2,-default- -value-,PROMPT3,-default- -value-,PROMPT4,-default- -value-,RPROMPT,-default- -value-,RPROMPT2,-default- -value-,PS1,-default- -value-,PS2,-default- -value-,PS3,-default- -value-,PS4,-default- -value-,RPS1,-default- -value-,RPS2,-default- -value-,SPROMPT,-default- -local -a specs +local -a specs ccol local expl grp cols bs suf pre changed=1 ret=1 local -A ansi @@ -39,7 +39,8 @@ if compset -P '%[FK]'; then _description -V ansi-colors expl 'ansi color' grp="$expl[expl[(i)-V]+1]" - _comp_colors+=( ${(ps.\0.)"$(printf "($grp)=%s=%s\0" ${(kv)ansi})"} ) + print -v ccol -f "($grp)=%s=%s" ${(kv)ansi} + _comp_colors+=( $ccol ) compadd "$expl[@]" $suf $pre -k ansi && ret=0 if (( $#suf )) && compset -P "(<->|%v)"; then _wanted ansi-colors expl 'closing brace' compadd -S '' \} && ret=0 @@ -58,11 +59,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=( diff --git a/Completion/Zsh/Type/_user_math_func b/Completion/Zsh/Type/_user_math_func index 16774f70b..35a49d50e 100644 --- a/Completion/Zsh/Type/_user_math_func +++ b/Completion/Zsh/Type/_user_math_func @@ -6,4 +6,4 @@ local -a funcs funcs=(${${${(f)"$(functions -M)"}##functions -M }%% *}) _wanted user-math-functions expl 'user math function' \ - compadd -S '(' "$@" -a funcs + compadd -S '(' -q "$@" -a funcs diff --git a/Completion/Zsh/Type/_vars b/Completion/Zsh/Type/_vars index 0f97d6cda..ec59c03be 100644 --- a/Completion/Zsh/Type/_vars +++ b/Completion/Zsh/Type/_vars @@ -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 diff --git a/Completion/Zsh/Type/_widgets b/Completion/Zsh/Type/_widgets new file mode 100644 index 000000000..fdab2814e --- /dev/null +++ b/Completion/Zsh/Type/_widgets @@ -0,0 +1,9 @@ +#autoload + +local expl pattern + +pattern=( -g \* ) +zparseopts -D -K -E g:=pattern + +_description widgets expl widget +compadd "$@" "$expl[@]" -M 'r:|-=* r:|=*' - "${(@k)widgets[(R)${pattern[2]}]}" |