From 640a840d2e94f0fc245ef8632050c37af23c6b94 Mon Sep 17 00:00:00 2001 From: Tanaka Akira Date: Thu, 15 Apr 1999 18:21:49 +0000 Subject: zsh-3.1.5-pws-13 --- Completion/Base/_brace_parameter | 2 +- Completion/Base/_long_options | 9 +++-- Completion/Base/_subscript | 13 +++---- Completion/Base/_vars | 2 +- Completion/Builtins/_cd | 2 +- Completion/Commands/_correct_filename | 47 +++++++++++++++++++++---- Completion/Core/_multi_parts | 65 ++++++++++++++++++++++++----------- Completion/Core/_path_files | 3 +- Completion/Core/compinit | 5 ++- Completion/README | 5 ++- Completion/User/_pdf | 2 +- 11 files changed, 108 insertions(+), 47 deletions(-) (limited to 'Completion') diff --git a/Completion/Base/_brace_parameter b/Completion/Base/_brace_parameter index 092376e78..3fab8510a 100644 --- a/Completion/Base/_brace_parameter +++ b/Completion/Base/_brace_parameter @@ -2,4 +2,4 @@ # Simple but without spiffy suffix handling: compgen -v -S '} ' -compadd -S '} ' -r '-:?#%+=[/' - "${(@)${${${(f)$(typeset)}%%\=*}##* }:gs/'//}" +compadd -S '} ' -r '-:?#%+=[/' - "${(@)${(@)${(@f)$(set)}%%\=*}:gs/'//}" diff --git a/Completion/Base/_long_options b/Completion/Base/_long_options index a5d92632c..cc3175592 100644 --- a/Completion/Base/_long_options +++ b/Completion/Base/_long_options @@ -2,9 +2,12 @@ # This function tries to automatically complete long option names. For # this it invokes the command from the line with the `--help' option -# and then parses the output to find possible option names. For -# options that get an argument after a `=', the function also tries to -# automatically find out what should be complete as the argument. +# and then parses the output to find possible option names, so you +# should be careful to make sure that this function is not called for +# a command that does not support this option. +# +# For options that get an argument after a `=', the function also tries +# to automatically find out what should be complete as the argument. # The possible completions for option-arguments can be described with # the arguments to this function. This is done by giving pairs of # patterns and actions as consecutive arguments. The actions specify diff --git a/Completion/Base/_subscript b/Completion/Base/_subscript index 670739a9a..e783d04e7 100644 --- a/Completion/Base/_subscript +++ b/Completion/Base/_subscript @@ -1,10 +1,7 @@ #defcomp -subscript- -local ret=1 - -_compalso -math- && ret=0 - -[[ ${(Pt)${compstate[parameter]}} = assoc* ]] && - compgen -k "( ${(kP)${compstate[parameter]}} )" && ret=0 - -return ret +if [[ ${(Pt)${compstate[parameter]}} = assoc* ]]; then + compgen -S ']' -k "( ${(kP)${compstate[parameter]}} )" +else + _compalso -math- +fi diff --git a/Completion/Base/_vars b/Completion/Base/_vars index 92de51e1f..497a9316f 100644 --- a/Completion/Base/_vars +++ b/Completion/Base/_vars @@ -1,3 +1,3 @@ -#defcomp -math- getopts read unset vared +#defcomp getopts read unset vared compgen -v diff --git a/Completion/Builtins/_cd b/Completion/Builtins/_cd index 9a58effe0..44443c3d5 100644 --- a/Completion/Builtins/_cd +++ b/Completion/Builtins/_cd @@ -59,7 +59,7 @@ elif [[ $words[1] = pu* && $PREFIX = [-+]* ]]; then return ret elif [[ $PREFIX != (\~|/|./|../)* && $#cdpath -ne 0 ]]; then - _path_files -W cdpath -/ + _path_files -W "(. $cdpath)" -/ else _path_files -/ fi diff --git a/Completion/Commands/_correct_filename b/Completion/Commands/_correct_filename index 582555587..27295738c 100644 --- a/Completion/Commands/_correct_filename +++ b/Completion/Commands/_correct_filename @@ -6,18 +6,46 @@ # # You can adapt max_approx to the maximum number of mistakes # which are allowed in total. +# +# If the numeric prefix is greater than 1, the maximum number of errors +# will be set to that. + +# Doesn't get right special characters in the filename; should +# strip them (e.g. "foo\ bar" -> "foo bar") and then re-insert them. emulate -LR zsh setopt extendedglob -local file="$PREFIX$SUFFIX" trylist +local file="$PREFIX$SUFFIX" trylist tilde etilde testcmd integer approx max_approx=6 -[[ -z $WIDGET ]] && file=$1 +if [[ -z $WIDGET ]]; then + file=$1 + local IPREFIX +else + (( NUMERIC > 1 )) && max_approx=$NUMERIC +fi + +if [[ $file = \~*/* ]]; then + tilde=${file%%/*} + etilde=${~tilde} + file=${file/#$tilde/$etilde} +fi + +if [[ $CURRENT -eq 1 && $file != /* ]]; then + testcmd=1 +elif [[ $file = \=* ]]; then + [[ -n $WIDGET ]] && PREFIX="$PREFIX[2,-1]" + IPREFIX="${IPREFIX}=" + file="$file[2,-1]" + testcmd=1 +fi -if [[ -e "$file" ]]; then +# We need the -Q's to avoid the tilde we've put back getting quoted. +if [[ -z $testcmd && -e "$file" ]] || + { [[ -n $testcmd ]] && whence "$file" >&/dev/null }; then if [[ -n $WIDGET ]]; then - compadd -U -i "$IPREFIX" "$file" + compadd -QUf -i "$IPREFIX" "${file/#$etilde/$tilde}" [[ -n "$compstate[insert]" ]] && compstate[insert]=menu else print "$file" @@ -26,14 +54,19 @@ if [[ -e "$file" ]]; then fi for (( approx = 1; approx <= max_approx; approx++ )); do - trylist=( (#a$approx)"$file"(N) ) + if [[ -z $testcmd ]]; then + trylist=( (#a$approx)"$file"(N) ) + else + trylist=( "${(@)${(@f)$(whence -wm "(#a$approx)$file" 2>/dev/null)}%:*}" ) + [[ $file = */* ]] || trylist=(${trylist##*/}) + fi (( $#trylist )) && break done (( $#trylist )) || return 1 if [[ -n $WIDGET ]]; then - compadd -U -i "$IPREFIX" -U "${trylist[@]}" + compadd -QUf -i "$IPREFIX" "${trylist[@]/#$etilde/$tilde}" [[ -n "$compstate[insert]" ]] && compstate[insert]=menu else - print "${trylist[@]}" + print "$IPREFIX${^trylist[@]}" fi diff --git a/Completion/Core/_multi_parts b/Completion/Core/_multi_parts index 1f51d2f6d..0c677aab7 100644 --- a/Completion/Core/_multi_parts +++ b/Completion/Core/_multi_parts @@ -8,7 +8,7 @@ # separator character are then completed independently. local sep matches patstr orig matchflags pref i tmp1 tmp2 nm -local group expl +local group expl menu origflags mflags _match_test _multi_parts || return 1 @@ -42,22 +42,25 @@ else fi # Now build the pattern from what we have on the line. We also save -# the original string in `orig'. The `eval' is used to replace our -# separator character by `*'. +# the original string in `orig'. -if [[ -o globcomplete ]]; then +if [[ $#compstate[pattern_match] -ne 0 ]]; then patstr="${PREFIX}*${SUFFIX}*" else patstr="${PREFIX:q}*${SUFFIX:q}*" fi orig="${PREFIX}${SUFFIX}" +[[ $compstate[insert] = *menu || -n "$_comp_correct" || + ( $#compstate[pattern_match] -ne 0 && + "$orig" != "${orig:q}" ) ]] && menu=yes + matchflags="" _match_pattern _path_files patstr matchflags +origflags="$matchflags" [[ -n "$_comp_correct" ]] && matchflags="$matchflags(#a$_comp_correct)" patstr="${${patstr//$sep/*$sep}//\*##/*}" -#eval patstr\="\$patstr:gs-${sep}-\*${sep}-:gs/\*\*/\*/" # First we will skip over those parts of the matches for which we have # exact substrings on the line. In `pref' we will build the @@ -70,19 +73,26 @@ while [[ "$orig" = *${sep}* ]] do # `matches' that match the prefix we have and the exact substring in # the array `tmp1'. - pat="${${${patstr#*${sep}}%${sep}*}//\*/[^${sep}]#}${patstr##*${sep}}" - tmp1=( "${(@M)matches:#${~matchflags}${orig%%${sep}*}${sep}${~pat}}" ) + if [[ -n "$_comp_correct" && "${#orig%%${sep}*}" -le _comp_correct ]]; then + mflags="$origflags" + else + mflags="$matchflags" + fi + + pat="${${${patstr#*${sep}}%${sep}*}//\*/[^${sep}]#}" + tmp1=( "${(@M)matches:#${~mflags}${orig%%${sep}*}${sep}${~pat}}" ) # If there are no words matching the exact substring, stop. (( $#tmp1 )) || break # Otherwise add the part to the prefix, remove it from the matches - # (which will also remove all words not matching the string at all), - # and set `patstr' and `orig' to the next component. + # (and also remove all words not matching the string at all), and + # set `patstr' and `orig' to the next component. - pref="$pref${orig%%${sep}*}${sep}" - matches=( "${(@)${(@)matches#${orig%%${sep}*}${sep}}:#}" ) + tmp1="${orig%%${sep}*}${sep}" + pref="$pref$tmp1" + matches=("${(@)${(@)${(@M)matches:#${tmp1}*}#$tmp1}:#}") orig="${orig#*${sep}}" patstr="${patstr#*${sep}}" done @@ -95,11 +105,16 @@ if [[ "$patstr" = *${sep}* ]]; then else pat="$patstr" fi -tmp1=( "${(@M)matches:#${~matchflags}${~pat}}" ) +if [[ -n "$_comp_correct" && "${#orig%%${sep}*}" -le _comp_correct ]]; then + mflags="$origflags" +else + mflags="$matchflags" +fi +tmp1=( "${(@M)matches:#${~mflags}${~pat}}" ) if (( $#tmp1 )); then - # There are words that are matched, put them int `matches' and then + # There are words that are matched, put them into `matches' and then # move all unambiguous components from the beginning into `pref'. matches=( "$tmp1[@]" ) @@ -113,7 +128,7 @@ if (( $#tmp1 )); then tmp2=( "${(@)matches:#${tmp1}*}" ) (( $#tmp2 )) && break - # All matches have the same prefix, but it into `pref' and remove + # All matches have the same prefix, put it into `pref' and remove # it from the matches. pref="$pref$tmp1" @@ -131,21 +146,26 @@ if (( $#tmp1 )); then if [[ -z "$orig" && "$PREFIX$SUFFIX" != "$pref$orig" ]]; then compadd -QU "$group[@]" "$expl[@]" -i "$IPREFIX" -S '' - "${pref}${orig}" - elif [[ $compstate[insert] = *menu ]]; then + elif [[ -n "$menu" ]]; then + if [[ "$orig" = *${sep}* ]]; then + orig="${sep}${orig#*${sep}}" + else + orig='' + fi for i in "$matches[@]" ; do if [[ "$i" = *${sep}* ]]; then compadd -U "$group[@]" "$expl[@]" -i "$IPREFIX" \ - -p "$pref" -qS "$sep" - "${i%%${sep}*}" + -p "$pref" -s "$orig" - "${i%%${sep}*}${sep}" else compadd -U "$group[@]" "$expl[@]" -i "$IPREFIX" \ - -p "$pref" - "${i%%${sep}*}" + -p "$pref" -s "$orig" - "${i%%${sep}*}" fi done else for i in "$matches[@]" ; do if [[ "$i" = *${sep}* ]]; then - compadd -U -i "$IPREFIX" -p "$pref" -s "${sep}${i#*${sep}}" \ - "$group[@]" "$expl[@]" -M "r:|${sep}=*" - "${i%%${sep}*}" + compadd -U -i "$IPREFIX" -p "$pref" -s "${i#*${sep}}" \ + "$group[@]" "$expl[@]" -M "r:|${sep:q}=*" - "${i%%${sep}*}${sep}" else compadd -U "$group[@]" "$expl[@]" -i "$IPREFIX" -p "$pref" - "$i" fi @@ -163,7 +183,12 @@ elif [[ "$patstr" = *${sep}* ]]; then # First we get all words matching at least this component in # `tmp1'. If there are none, we give up. - tmp1=( "${(@M)matches:#${~matchflags}${~patstr%%${sep}*}${sep}*}" ) + if [[ -n "$_comp_correct" && "${#orig%%${sep}*}" -le _comp_correct ]]; then + mflags="$origflags" + else + mflags="$matchflags" + fi + tmp1=( "${(@M)matches:#${~mflags}${~patstr%%${sep}*}${sep}*}" ) (( $#tmp1 )) || break # Then we check if there are words that have a different prefix. diff --git a/Completion/Core/_path_files b/Completion/Core/_path_files index 535ba537c..4c61ac7ef 100644 --- a/Completion/Core/_path_files +++ b/Completion/Core/_path_files @@ -111,7 +111,7 @@ orig="${PREFIX}${SUFFIX}" [[ $compstate[insert] = *menu || -n "$_comp_correct" || ( $#compstate[pattern_match] -ne 0 && - "$orig" != "${orig:q}" ) ]] && menu=yes + "${orig#\~}" != "${${orig#\~}:q}" ) ]] && menu=yes # We will first try normal completion called with `compgen', but only if we @@ -405,6 +405,7 @@ for prepath in "$prepaths[@]"; do # No match, insert the expanded path and add the original tail. [[ "$testpath[-1]" = / ]] && testpath="$testpath[1,-2]" + [[ -z "$testpath" && "$linepath[-1]" = / ]] && linepath="$linepath[1,-2]" [[ -n "$ostr" && -n "$linepath$testpath" ]] && ostr="/$ostr" # But only if something changed. diff --git a/Completion/Core/compinit b/Completion/Core/compinit index 31d011565..466c80d36 100644 --- a/Completion/Core/compinit +++ b/Completion/Core/compinit @@ -221,12 +221,11 @@ compdef() { # set key `baz' to the empty string. compconf() { - local i name + local i for i; do if [[ "$i" = *\=* ]]; then - name="${i%%\=*}" - compconfig[$name]="${i#*\=}" + compconfig[${i%%\=*}]="${i#*\=}" else compconfig[$i]='' fi diff --git a/Completion/README b/Completion/README index f95e67699..931d14355 100644 --- a/Completion/README +++ b/Completion/README @@ -74,7 +74,10 @@ Base: This handles options beginning with `--', as in many GNU commands. The command must accept the --help option to list the possible options. __long_options can also take arguments to help it decide what to - complete as the value of the option. + complete as the value of the option. Note that this is potentially + dangerous because the command from the line will be called with the + --help option and hence could cause damage if used with a command + that does not support it. _match_pattern _match_test These are used by Base/_path_files (and hence also Base/_files) diff --git a/Completion/User/_pdf b/Completion/User/_pdf index 7d7756c3e..11abc216b 100644 --- a/Completion/User/_pdf +++ b/Completion/User/_pdf @@ -1,3 +1,3 @@ -function acroread +#defcomp acroread _files -g '*.(pdf|PDF)' -- cgit 1.4.1