diff options
Diffstat (limited to 'Completion/Core')
-rw-r--r-- | Completion/Core/_compalso | 6 | ||||
-rw-r--r-- | Completion/Core/_complete | 7 | ||||
-rw-r--r-- | Completion/Core/_normal | 12 | ||||
-rw-r--r-- | Completion/Core/compdump | 11 | ||||
-rw-r--r-- | Completion/Core/compinit | 62 |
5 files changed, 73 insertions, 25 deletions
diff --git a/Completion/Core/_compalso b/Completion/Core/_compalso index 8df6b4a6f..5307bf30c 100644 --- a/Completion/Core/_compalso +++ b/Completion/Core/_compalso @@ -7,11 +7,11 @@ # `_compalso -math-' to get the completions that would be generated for a # mathematical context. -local i tmp ret=1 +local i tmp ret=1 service for i; do - tmp="$_comps[$1]" - [[ -z "$tmp" ]] || "$tmp" && ret=0 + tmp="$_comps[$i]" + [[ -z "$tmp" ]] || service="${_services[$i]:-$i}" && "$tmp" && ret=0 done return ret diff --git a/Completion/Core/_complete b/Completion/Core/_complete index 809df1fa9..28bb008ca 100644 --- a/Completion/Core/_complete +++ b/Completion/Core/_complete @@ -4,7 +4,7 @@ # a normal completion function, but as one possible value for the # completer style. -local comp name oldcontext ret=1 +local comp name oldcontext ret=1 service typeset -T curcontext="$curcontext" ccarray oldcontext="$curcontext" @@ -95,6 +95,7 @@ fi comp="$_comps[-first-]" if [[ ! -z "$comp" ]]; then + service="${_services[-first-]:--first-}" ccarray[3]=-first- "$comp" && ret=0 if [[ "$_compskip" = all ]]; then @@ -123,6 +124,7 @@ else ccarray[3]="$cname" comp="$_comps[$cname]" + service="${_services[$cname]:-$cname}" # If not, we use default completion, if any. @@ -133,7 +135,8 @@ else fi comp="$_comps[-default-]" fi - [[ -z "$comp" ]] || "$comp" && ret=0 + [[ -z "$comp" ]] || + service="${_services[-default-]:--default-}" && "$comp" && ret=0 fi _compskip= diff --git a/Completion/Core/_normal b/Completion/Core/_normal index 54767f2f6..02229835a 100644 --- a/Completion/Core/_normal +++ b/Completion/Core/_normal @@ -1,7 +1,7 @@ #compdef -command-line- local comp command cmd1 cmd2 pat val name i ret=1 _compskip="$_compskip" -local curcontext="$curcontext" +local curcontext="$curcontext" service # If we get the option `-s', we don't reset `_compskip'. This ensures # that a value set in the function for the `-first-' context is kept, @@ -44,6 +44,7 @@ fi # See if there are any matching pattern completions. if [[ "$_compskip" != (all|*patterns*) ]]; then + service="${_services[$cmd1]:-$cmd1}" for i in "${(@)_patcomps[(K)$cmd1]}"; do "$i" && ret=0 if [[ "$_compskip" = *patterns* ]]; then @@ -54,6 +55,7 @@ if [[ "$_compskip" != (all|*patterns*) ]]; then fi done if [[ -n "$cmd2" ]]; then + service="${_services[$cmd2]:-$cmd2}" for i in "${(@)_patcomps[(K)$cmd2]}"; do "$i" && ret=0 if [[ "$_compskip" = *patterns* ]]; then @@ -71,8 +73,10 @@ fi ret=1 name="$cmd1" comp="$_comps[$cmd1]" +service="${_services[$cmd1]:-$cmd1}" -[[ -z "$comp" ]] && name="$cmd2" comp="$_comps[$cmd2]" +[[ -z "$comp" ]] && + name="$cmd2" comp="$_comps[$cmd2]" service="${_services[$cmd2]:-$cmd2}" # And generate the matches, probably using default completion. @@ -86,6 +90,7 @@ elif [[ "$_compskip" != *default* ]]; then fi if [[ "$_compskip" != (all|*patterns*) ]]; then + service="${_services[$cmd1]:-$cmd1}" for i in "${(@)_postpatcomps[(K)$cmd1]}"; do _compskip=default "$i" && ret=0 @@ -97,6 +102,7 @@ if [[ "$_compskip" != (all|*patterns*) ]]; then fi done if [[ -n "$cmd2" ]]; then + service="${_services[$cmd2]:-$cmd2}" for i in "${(@)_postpatcomps[(K)$cmd2]}"; do _compskip=default "$i" && ret=0 @@ -111,7 +117,7 @@ if [[ "$_compskip" != (all|*patterns*) ]]; then fi [[ "$name" = -default- && -n "$comp" && "$_compskip" != (all|*default*) ]] && - "$comp" && ret=0 + service="${_services[-default-]:--default-}" && "$comp" && ret=0 _compskip='' diff --git a/Completion/Core/compdump b/Completion/Core/compdump index 25df17fbf..a94a41df6 100644 --- a/Completion/Core/compdump +++ b/Completion/Core/compdump @@ -35,8 +35,9 @@ fi print "#files: $#_d_files" > $_d_file -# First dump the arrays _comps and _patcomps. The quoting hieroglyphyics -# ensure that a single quote inside a variable is itself correctly quoted. +# First dump the arrays _comps, _services and _patcomps. The quoting +# hieroglyphyics ensure that a single quote inside a variable is itself +# correctly quoted. print "_comps=(" >> $_d_file for _d_f in ${(ok)_comps}; do @@ -44,6 +45,12 @@ for _d_f in ${(ok)_comps}; do done >> $_d_file print ")" >> $_d_file +print "_services=(" >> $_d_file +for _d_f in ${(ok)_services}; do + print -r - "${(q)_d_f}" "${(q)_services[$_d_f]}" +done >> $_d_file +print ")" >> $_d_file + print "\n_patcomps=(" >> $_d_file for _d_f in "${(ok@)_patcomps}"; do print -r - "${(q)_d_f}" "${(q)_patcomps[$_d_f]}" diff --git a/Completion/Core/compinit b/Completion/Core/compinit index 86e4204f0..4203bcbc7 100644 --- a/Completion/Core/compinit +++ b/Completion/Core/compinit @@ -100,12 +100,13 @@ while [[ $# -gt 0 && $1 = -[dDiuC] ]]; do esac done -# The associative array containing the definitions for the commands. +# The associative array containing the definitions for the commands and +# services. # Definitions for patterns will be stored in the associations `_patcomps' # and `_postpatcomps'. `_compautos' contains the names and options # for autoloaded functions that get options. -typeset -gA _comps _patcomps _postpatcomps _compautos +typeset -gA _comps _services _patcomps _postpatcomps _compautos # The associative array use to report information about the last # cmpletion to the outside. @@ -198,12 +199,12 @@ comppostfuncs=() # delete the definitions for the command names `bar' and `baz' compdef() { - local opt autol type func delete new i + local opt autol type func delete new i ret=0 cmd svc # Get the options. if [[ $#* -eq 0 ]]; then - echo "compdef needs parameters" + echo "$0: I needs arguments" return 1 fi @@ -233,11 +234,38 @@ compdef() { shift OPTIND-1 if [[ $#* -eq 0 ]]; then - echo "compdef needs parameters" + echo "$0: I needs arguments" return 1 fi if [[ -z "$delete" ]]; then + # If the first word contains an equal sign, all words must contain one + # and we define which services to use for the commands. + + if [[ "$1" = *\=* ]]; then + for i; do + if [[ "$i" = *\=* ]]; then + cmd="${i%%\=*}" + svc="${i#*\=}" + func="$_comps[${(k)_services[(R)$svc]:-$svc}]" + [[ -z "$func" ]] && + func="${_patcomps[(K)$svc][1]:-${_postpatcomps[(K)$svc][1]}}" + if [[ -n "$func" ]]; then + _comps[$cmd]="$func" + _services[$cmd]="$svc" + else + echo "$0: unknown command or service: $svc" + ret=1 + fi + else + echo "$0: invalid argument: $i" + ret=1 + fi + done + + return ret + fi + # Adding definitions, first get the name of the function name # and probably do autoloading. @@ -307,15 +335,19 @@ compdef() { *) # For commands store the function name in the `_comps' # associative array, command names as keys. - if [[ -z "$new" ]]; then - for i; do - _comps[$i]="$func" - done - else - for i; do - [[ "${+_comps[$i]}" -eq 0 ]] && _comps[$i]="$func" - done - fi + for i; do + if [[ "$i" = *\=* ]]; then + cmd="${i%%\=*}" + svc=yes + else + cmd="$i" + svc= + fi + if [[ -z "$new" || "${+_comps[$i]}" -eq 0 ]]; then + _comps[$cmd]="$func" + [[ -n "$svc" ]] && _services[$cmd]="${i#*\=}" + fi + done ;; esac else @@ -331,7 +363,7 @@ compdef() { # Oops, cannot do that yet. echo "$0: cannot restore key bindings" - return 1 + return 1v ;; *) unset "_comps[$^@]" |