diff options
Diffstat (limited to 'Completion/Base')
-rw-r--r-- | Completion/Base/Completer/_expand | 11 | ||||
-rw-r--r-- | Completion/Base/Core/_description | 10 | ||||
-rw-r--r-- | Completion/Base/Core/_main_complete | 16 | ||||
-rw-r--r-- | Completion/Base/Core/_message | 2 | ||||
-rw-r--r-- | Completion/Base/Utility/_arguments | 22 | ||||
-rw-r--r-- | Completion/Base/Utility/_call_program | 1 | ||||
-rw-r--r-- | Completion/Base/Utility/_numbers | 87 | ||||
-rw-r--r-- | Completion/Base/Utility/_sequence | 4 | ||||
-rw-r--r-- | Completion/Base/Utility/_store_cache | 2 | ||||
-rw-r--r-- | Completion/Base/Utility/_values | 2 | ||||
-rw-r--r-- | Completion/Base/Widget/_bash_completions | 2 | ||||
-rw-r--r-- | Completion/Base/Widget/_complete_debug | 6 | ||||
-rw-r--r-- | Completion/Base/Widget/_complete_help | 2 | ||||
-rw-r--r-- | Completion/Base/Widget/_complete_tag | 4 |
14 files changed, 142 insertions, 29 deletions
diff --git a/Completion/Base/Completer/_expand b/Completion/Base/Completer/_expand index def522a76..e5e4f9b39 100644 --- a/Completion/Base/Completer/_expand +++ b/Completion/Base/Completer/_expand @@ -11,7 +11,7 @@ setopt localoptions nonomatch [[ _matcher_num -gt 1 ]] && return 1 -local exp word sort expr expl subd suf=" " force opt asp tmp opre pre epre +local exp word sort expr expl subd pref suf=" " force opt asp tmp opre pre epre local continue=0 (( $# )) && @@ -105,7 +105,7 @@ subd=("$exp[@]") # We need to come out of this with consistent quoting, by hook or by crook. integer done_quote -local orig_exp=$exp +local -a orig_exp=( $exp ) if [[ "$force" = *g* ]] || zstyle -T ":completion:${curcontext}:" glob; then eval 'exp=( ${~exp//(#b)\\([ \"'"\'"' ])/$match[1]} ); exp=( ${(q)exp} )' 2>/dev/null && (( $#exp )) && done_quote=1 @@ -214,9 +214,10 @@ else normal=( "$normal[@]" "$i" ) fi done - (( $#dir )) && compadd "$expl[@]" -UQ -qS/ -a dir - (( $#space )) && compadd "$expl[@]" -UQ -qS " " -a space - (( $#normal )) && compadd "$expl[@]" -UQ -qS "" -a normal + pref="${${word:#[~/]*}:+$PWD}/" + (( $#dir )) && compadd "$expl[@]" -fW "$pref" -UQ -qS/ -a dir + (( $#space )) && compadd "$expl[@]" -fW "$pref" -UQ -qS " " -a space + (( $#normal )) && compadd "$expl[@]" -fW "$pref" -UQ -qS "" -a normal fi if _requested all-expansions; then local disp dstr diff --git a/Completion/Base/Core/_description b/Completion/Base/Core/_description index bdb4007a6..368b41ee2 100644 --- a/Completion/Base/Core/_description +++ b/Completion/Base/Core/_description @@ -2,6 +2,7 @@ local name nopt xopt format gname hidden hide match opts tag local -a ign gropt sort +local -a match mbegin mend opts=() @@ -78,7 +79,14 @@ shift 2 if [[ -z "$1" && $# -eq 1 ]]; then format= elif [[ -n "$format" ]]; then - zformat -f format "$format" "d:$1" "${(@)argv[2,-1]}" + if [[ -z $2 ]]; then + argv+=( h:${1%%( ##\((#b)([^\)]#[^0-9-][^\)]#)(#B)\)|)( ##\((#b)([0-9-]##)(#B)\)|)( ##\[(#b)([^\]]##)(#B)\]|)} ) + [[ -n $match[1] ]] && argv+=( m:$match[1] ) + [[ -n $match[2] ]] && argv+=( r:$match[2] ) + [[ -n $match[3] ]] && argv+=( o:$match[3] ) + fi + + zformat -F format "$format" "d:$1" "${(@)argv[2,-1]}" fi if [[ -n "$gname" ]]; then diff --git a/Completion/Base/Core/_main_complete b/Completion/Base/Core/_main_complete index 6b2cf2bcf..169ca1f40 100644 --- a/Completion/Base/Core/_main_complete +++ b/Completion/Base/Core/_main_complete @@ -94,8 +94,18 @@ if [[ -z "$compstate[quote]" ]]; then if [[ -o equals ]] && compset -P 1 '='; then compstate[context]=equal elif [[ "$PREFIX" != */* && "$PREFIX[1]" = '~' ]]; then - compset -p 1 - compstate[context]=tilde + if [[ "$PREFIX" = '~['[^\]]# ]]; then + # Inside ~[...] should be treated as a subscript. + compset -p 2 + # To be consistent, we ignore all but the contents of the square + # brackets. + compset -S '\]*' + compstate[context]=subscript + [[ -n $_comps[-subscript-] ]] && $_comps[-subscript-] && return + else + compset -p 1 + compstate[context]=tilde + fi fi fi @@ -234,7 +244,7 @@ if [[ $compstate[old_list] = keep || nm -gt 1 ]]; then _menu_style=( "$_menu_style[@]" "$_def_menu_style[@]" ) - if [[ "$compstate[list]" = *list && tmp -gt LINES && + if [[ "$compstate[list]" = *list(| *) && tmp -gt LINES && ( -n "$_menu_style[(r)select=long-list]" || -n "$_menu_style[(r)(yes|true|on|1)=long-list]" ) ]]; then compstate[insert]=menu diff --git a/Completion/Base/Core/_message b/Completion/Base/Core/_message index 4d5645eaf..dbeed4a88 100644 --- a/Completion/Base/Core/_message +++ b/Completion/Base/Core/_message @@ -39,7 +39,7 @@ else fi if [[ -n "$format$raw" ]]; then - [[ -z "$raw" ]] && zformat -f format "$format" "d:$1" "${(@)argv[2,-1]}" + [[ -z "$raw" ]] && zformat -F format "$format" "d:$1" "${(@)argv[2,-1]}" builtin compadd "$gopt[@]" -x "$format" _comp_mesg=yes fi diff --git a/Completion/Base/Utility/_arguments b/Completion/Base/Utility/_arguments index 136dd5826..5ff34ff47 100644 --- a/Completion/Base/Utility/_arguments +++ b/Completion/Base/Utility/_arguments @@ -7,11 +7,13 @@ local long cmd="$words[1]" descr odescr mesg subopts opt opt2 usecc autod local oldcontext="$curcontext" hasopts rawret optarg singopt alwopt local setnormarg start rest local -a match mbegin mend +integer opt_args_use_NUL_separators=0 subopts=() singopt=() -while [[ "$1" = -([AMO]*|[CRSWnsw]) ]]; do +while [[ "$1" = -([AMO]*|[0CRSWnsw]) ]]; do case "$1" in + -0) opt_args_use_NUL_separators=1; shift ;; -C) usecc=yes; shift ;; -O) subopts=( "${(@P)2}" ); shift 2 ;; -O*) subopts=( "${(@P)${1[3,-1]}}" ); shift ;; @@ -130,8 +132,8 @@ if (( long )); then # variant syntax seen in fetchmail: # --[fetch]all means --fetchall or --all. # maybe needs to be more general - if [[ $start = (#b)(*)\[(*)\](*) ]]; then - tmp+=("${match[1]}${match[2]}${match[3]}" "${match[1]}${match[3]}") + if [[ $start = (#b)--\[(*)\](*) ]]; then + tmp+=("--${match[1]}${match[2]}" "--${match[2]}") else tmp+=($start) fi @@ -388,7 +390,7 @@ if (( $# )) && comparguments -i "$autod" "$singopt[@]" "$@"; then if [[ "$action" = -\>* ]]; then action="${${action[3,-1]##[ ]#}%%[ ]#}" if (( ! $state[(I)$action] )); then - comparguments -W line opt_args + comparguments -W line opt_args $opt_args_use_NUL_separators state+=( "$action" ) state_descr+=( "$descr" ) if [[ -n "$usecc" ]]; then @@ -406,7 +408,7 @@ if (( $# )) && comparguments -i "$autod" "$singopt[@]" "$@"; then local=yes fi - comparguments -W line opt_args + comparguments -W line opt_args $opt_args_use_NUL_separators if [[ "$action" = \ # ]]; then @@ -511,8 +513,8 @@ if (( $# )) && comparguments -i "$autod" "$singopt[@]" "$@"; then tmp2=( "${PREFIX}${(@M)^${(@)${(@)tmp1%%:*}#[-+]}:#?}" ) _describe -O option \ - tmp1 tmp2 -Q -S '' -- \ - tmp3 -Q + tmp1 tmp2 -S '' -- \ + tmp3 [[ -n "$optarg" && "$single" = next && nm -eq $compstate[nmatches] ]] && _all_labels options expl option \ @@ -523,9 +525,9 @@ if (( $# )) && comparguments -i "$autod" "$singopt[@]" "$@"; then else next+=( "$odirect[@]" ) _describe -O option \ - next -Q -M "$matcher" -- \ - direct -QS '' -M "$matcher" -- \ - equal -QqS= -M "$matcher" + next -M "$matcher" -- \ + direct -S '' -M "$matcher" -- \ + equal -qS= -M "$matcher" fi PREFIX="$prevpre" IPREFIX="$previpre" diff --git a/Completion/Base/Utility/_call_program b/Completion/Base/Utility/_call_program index 73f3ef6d2..55712b04b 100644 --- a/Completion/Base/Utility/_call_program +++ b/Completion/Base/Utility/_call_program @@ -1,5 +1,6 @@ #autoload +X +local -xi COLUMNS=999 local curcontext="${curcontext}" tmp err_fd=-1 clocale='_comp_locale;' local -a prefix diff --git a/Completion/Base/Utility/_numbers b/Completion/Base/Utility/_numbers new file mode 100644 index 000000000..97bb8b4c8 --- /dev/null +++ b/Completion/Base/Utility/_numbers @@ -0,0 +1,87 @@ +#autoload + +# Usage: _numbers [compadd options] [-t tag] [-f|-N] [-u units] [-l min] [-m max] \ +# [-d default] ["description"] [unit-suffix...] + +# -t : specify a tag (defaults to 'numbers') +# -u : indicate the units, e.g. seconds +# -l : lowest possible value +# -m : maximum possible value +# -d : default value +# -N : allow negative numbers (implied by range including a negative) +# -f : allow decimals (float) + +# For a unit-suffix, an initial colon indicates a unit that asserts the default +# otherwise, colons allow for descriptions, e.g: + +# :s:seconds m:minutes h:hours + +# unit-suffixes are not sorted by the completion system when listed +# Specify them in order of magnitude, this tends to be ascending unless +# the default is of a higher magnitude, in which case, descending. +# So for, example +# bytes kB MB GB +# s ms us ns +# Where the compadd options include matching control or suffixes, these +# are applied to the units + +# For each unit-suffix, the format style is looked up with the +# unit-suffixes tag and the results concatenated. Specs used are: +# x : the suffix +# X : suffix description +# d : indicate suffix is for the default unit +# i : list index +# r : reverse list index +# The latter three of these are useful with ternary expressions. + +# _description is called with the x token set to make the completed +# list of suffixes available to the normal format style + +local desc tag range suffixes suffix suffixfmt pat='<->' partial='' +local -a expl formats +local -a default max min keep tags units +local -i i +local -A opts + +zparseopts -K -D -A opts M+:=keep q:=keep s+:=keep S+:=keep J+: V+: 1 2 o+: n F: x+: X+: \ + t:=tags u:=units l:=min m:=max d:=default f=type e=type N=type + +desc="${1:-number}" tag="${tags[2]:-numbers}" +(( $# )) && shift + +[[ -n ${(M)type:#-f} ]] && pat='(<->.[0-9]#|[0-9]#.<->|<->)' partial='(|.)' +[[ -n ${(M)type:#-N} || $min[2] = -* || $max[2] = -* ]] && \ + pat="(|-)$pat" partial="(|-)$partial" + +if (( $#argv )) && compset -P "$pat"; then + zstyle -s ":completion:${curcontext}:units" list-separator sep || sep=-- + _description -V units expl unit + disp=( ${${argv#:}/:/ $sep } ) + compadd -M 'r:|/=* r:|=*' -d disp "$keep[@]" "$expl[@]" - ${${argv#:}%%:*} + return +elif [[ -prefix $~pat || $PREFIX = $~partial ]]; then + formats=( "h:$desc" ) + (( $#units )) && formats+=( m:${units[2]} ) desc+=" ($units[2])" + (( $#min )) && range="$min[2]-" + (( $#max )) && range="${range:--}$max[2]" + [[ -n $range ]] && formats+=( r:$range ) desc+=" ($range)" + (( $#default )) && formats+=( o:${default[2]} ) desc+=" [$default[2]]" + + zstyle -s ":completion:${curcontext}:unit-suffixes" format suffixfmt || \ + suffixfmt='%(d.%U.)%x%(d.%u.)%(r..|)' + for ((i=0;i<$#;i++)); do + zformat -f suffix "$suffixfmt" "x:${${argv[i+1]#:}%%:*}" \ + "X:${${argv[i+1]#:}#*:}" "d:${#${argv[i+1]}[1]#:}" \ + i:i r:$(( $# - i - 1)) + suffixes+="$suffix" + done + [[ -n $suffixes ]] && formats+=( x:$suffixes ) + + _comp_mesg=yes + _description -x $tag expl "$desc" $formats + [[ $compstate[insert] = *unambiguous* ]] && compstate[insert]= + compadd "$expl[@]" + return 0 +fi + +return 1 diff --git a/Completion/Base/Utility/_sequence b/Completion/Base/Utility/_sequence index c1ff32184..1a87c1753 100644 --- a/Completion/Base/Utility/_sequence +++ b/Completion/Base/Utility/_sequence @@ -8,10 +8,10 @@ # -d : duplicate values allowed local curcontext="$curcontext" nm="$compstate[nmatches]" pre qsep nosep minus -local -a opts sep num pref suf cont end uniq dedup +local -a opts sep num pref suf cont end uniq dedup garbage zparseopts -D -a opts s:=sep n:=num p:=pref i:=pref P:=pref I:=suf S:=suf \ - q=suf r:=suf R:=suf C:=cont d=uniq M+: J+: V+: 1 2 o+: X+: x+: + q=suf r:=suf R:=suf C:=cont F:=garbage d=uniq M+: J+: V+: 1 2 o+: X+: x+: (( $#cont )) && curcontext="${curcontext%:*}:$cont[2]" (( $#sep )) || sep[2]=, diff --git a/Completion/Base/Utility/_store_cache b/Completion/Base/Utility/_store_cache index fb2ab328a..b08ff1142 100644 --- a/Completion/Base/Utility/_store_cache +++ b/Completion/Base/Utility/_store_cache @@ -2,7 +2,7 @@ # # Storage component of completions caching layer -local _cache_ident _cache_ident_dir +local _cache_ident _cache_ident_dir _cache_dir _cache_ident="$1" if zstyle -t ":completion:${curcontext}:" use-cache; then diff --git a/Completion/Base/Utility/_values b/Completion/Base/Utility/_values index 6e38e00f4..688ada848 100644 --- a/Completion/Base/Utility/_values +++ b/Completion/Base/Utility/_values @@ -4,7 +4,7 @@ local subopts opt usecc garbage keep subopts=() zparseopts -D -a garbage s+:=keep S+:=keep w+=keep C=usecc O:=subopts \ - M: J: V: 1 2 n F: X: + M: J: V: 1 2 o+: n F: X: (( $#subopts )) && subopts=( "${(@P)subopts[2]}" ) diff --git a/Completion/Base/Widget/_bash_completions b/Completion/Base/Widget/_bash_completions index 7abb654d4..feb721451 100644 --- a/Completion/Base/Widget/_bash_completions +++ b/Completion/Base/Widget/_bash_completions @@ -32,7 +32,7 @@ local key=$KEYS[-1] expl case $key in '!') _main_complete _command_names ;; - '$') _main_complete - parameters _wanted parameters expl 'exported parameters' \ + '$') _main_complete - parameters _wanted parameters expl 'exported parameter' \ _parameters -g '*export*' ;; '@') _main_complete _hosts diff --git a/Completion/Base/Widget/_complete_debug b/Completion/Base/Widget/_complete_debug index 85a0f372a..94fd4accd 100644 --- a/Completion/Base/Widget/_complete_debug +++ b/Completion/Base/Widget/_complete_debug @@ -14,7 +14,11 @@ integer debug_fd=-1 exec {debug_fd}>&2 2>| $tmp fi - local -a debug_indent; debug_indent=( '%'{3..20}'(e. .)' ) + local -a debug_indent + () { + setopt localoptions no_ignorebraces + debug_indent=( '%'{3..20}'(e. .)' ) + } local PROMPT4 PS4="${(j::)debug_indent}+%N:%i> " setopt xtrace : $ZSH_NAME $ZSH_VERSION diff --git a/Completion/Base/Widget/_complete_help b/Completion/Base/Widget/_complete_help index 252b0e281..69855de9d 100644 --- a/Completion/Base/Widget/_complete_help +++ b/Completion/Base/Widget/_complete_help @@ -84,7 +84,7 @@ _help_sort_tags() { [[ "$help_funcs[$curcontext]" != *${f}* ]] && help_funcs[$curcontext]+=$'\0'"${f}" help_tags[${curcontext}${f}]+=",${argv}:${f}" - comptry "$@" + comptry "$@" 2>/dev/null fi } diff --git a/Completion/Base/Widget/_complete_tag b/Completion/Base/Widget/_complete_tag index 5b50f1d85..397b8d901 100644 --- a/Completion/Base/Widget/_complete_tag +++ b/Completion/Base/Widget/_complete_tag @@ -50,13 +50,13 @@ if [[ -f $c_path$c_Tagsfile ]]; then -e '/^[a-zA-Z_].*/p' $c_path$c_Tagsfile)) # c_tags_array=($(perl -ne '/([a-zA-Z_0-9]+)[ \t:;,\(]*\x7f/ && # print "$1\n"' $c_path$c_Tagsfile)) - _main_complete - '' _wanted etags expl 'emacs tags' \ + _main_complete - '' _wanted etags expl 'emacs tag' \ compadd -a c_tags_array elif [[ -f $c_path$c_tagsfile ]]; then # tags doesn't have as much in, but the tag is easy to find. # we can use awk here. c_tags_array=($(awk '{ print $1 }' $c_path$c_tagsfile)) - _main_complete - '' _wanted vtags expl 'vi tags' compadd -a c_tags_array + _main_complete - '' _wanted vtags expl 'vi tag' compadd -a c_tags_array else return 1 fi |