From 53d36e795b26a945048e7a87a1a91224f8e1663a Mon Sep 17 00:00:00 2001 From: Tanaka Akira Date: Sun, 2 May 1999 15:19:50 +0000 Subject: zsh-3.1.5-pws-17 --- Completion/Builtins/_stat | 10 ++ Completion/Core/.distfiles | 7 +- Completion/Core/_closequotes | 11 +++ Completion/Core/_menu | 21 +++++ Completion/Core/_multi_parts | 3 +- Completion/Core/_oldlist | 29 ++++++ Completion/Core/_path_files | 17 +--- Completion/Core/compinstall | 216 +++++++++++++++++++++++++++++++++++++++++++ Completion/User/_make | 2 +- 9 files changed, 298 insertions(+), 18 deletions(-) create mode 100644 Completion/Builtins/_stat create mode 100644 Completion/Core/_closequotes create mode 100644 Completion/Core/_menu create mode 100644 Completion/Core/_oldlist create mode 100644 Completion/Core/compinstall (limited to 'Completion') diff --git a/Completion/Builtins/_stat b/Completion/Builtins/_stat new file mode 100644 index 000000000..3cdbb2618 --- /dev/null +++ b/Completion/Builtins/_stat @@ -0,0 +1,10 @@ +#compdef stat + +if [[ "$words[CURRENT-1]" = -[AH] ]]; then + compgen -A +else + [[ "$PREFIX[1]" = + ]] && + compadd - +device +inode +mode +nlink +uid +gid +rdev +size \ + +atime +mtime +ctime +blksize +block +link + _files +fi diff --git a/Completion/Core/.distfiles b/Completion/Core/.distfiles index 6babe9701..9a9e87d7c 100644 --- a/Completion/Core/.distfiles +++ b/Completion/Core/.distfiles @@ -1,6 +1,7 @@ DISTFILES_SRC=' .distfiles - _approximate _compalso _complete _correct _expand _files _list - _main_complete _match _multi_parts _normal _options _parameters - _path_files _sep_parts _set_options _unset_options compdump compinit + _approximate _closequotes _compalso _complete _correct _expand _files + _list _main_complete _match _menu _multi_parts _normal _oldlist _options + _parameters _path_files _sep_parts _set_options _unset_options + compdump compinit compinstall ' diff --git a/Completion/Core/_closequotes b/Completion/Core/_closequotes new file mode 100644 index 000000000..2c4b390e5 --- /dev/null +++ b/Completion/Core/_closequotes @@ -0,0 +1,11 @@ +#autoload + +# If the current completion is in quotes, add the closing quote. +# This can clash with some of the more sophisticated forms of completion + +if [[ -n $compstate[quote] && $RBUFFER != *${compstate[quote]}* ]]; then + compstate[restore]='' + ISUFFIX="$ISUFFIX$compstate[quote]" +fi + +return 1 diff --git a/Completion/Core/_menu b/Completion/Core/_menu new file mode 100644 index 000000000..4cbda4e14 --- /dev/null +++ b/Completion/Core/_menu @@ -0,0 +1,21 @@ +#autoload + +# This completer is an example showing how menucompletion can be +# implemented with the new completion system. +# Use this one before the normal _complete completer, as in: +# +# compconf completer=_menu:_complete + +if [[ -n "$compstate[old_list]" ]]; then + + # We have an old list, keep it and insert the next match. + + compstate[old_list]=keep + compstate[insert]=$((compstate[old_insert]+1)) +else + # No old list, make completion insert the first match. + + compstate[insert]=1 +fi + +return 1 diff --git a/Completion/Core/_multi_parts b/Completion/Core/_multi_parts index b49c41e22..392277f94 100644 --- a/Completion/Core/_multi_parts +++ b/Completion/Core/_multi_parts @@ -83,8 +83,7 @@ while true; do else # No exact match, see how many strings match what's on the line. - tmp2=( "${(@)matches%%${sep}*}" ) - compadd -O tmp1 - "$tmp2[@]" + compadd -O tmp1 - "${(@)matches%%${sep}*}" if [[ $#tmp1 -eq 1 ]]; then diff --git a/Completion/Core/_oldlist b/Completion/Core/_oldlist new file mode 100644 index 000000000..f42197695 --- /dev/null +++ b/Completion/Core/_oldlist @@ -0,0 +1,29 @@ +#autoload + +# If this is a listing widget and there is already an old list, +# and either the compconfig key oldlist_list is `always', or it is not `never' +# and the list is not already shown, then use the existing list for listing +# (even if it was generated by another widget). +if [[ -n $compstate[old_list] && $compconfig[oldlist_list] != never && + $WIDGET = *list* && + ( $compconfig[oldlist_list] = always || $compstate[old_list] != shown ) ]] +then + compstate[old_list]=keep + return 0 +fi + +# If this is a completion widget, and we have a completion inserted already, +# and the compconfig key oldlist_menu is not never, then we cycle through the +# existing list (even if it was generated by another widget). +if [[ -n $compstate[old_insert] && $WIDGET = *complete(|-prefix|-word) && + $compconfig[oldlist_menu] != never ]]; then + compstate[old_list]=keep + if [[ $WIDGET = *reverse* ]]; then + compstate[insert]=$(( compstate[old_insert] - 1 )) + else + compstate[insert]=$(( compstate[old_insert] + 1 )) + fi + return 0 +fi + +return 1 diff --git a/Completion/Core/_path_files b/Completion/Core/_path_files index ed799be84..16666909b 100644 --- a/Completion/Core/_path_files +++ b/Completion/Core/_path_files @@ -230,14 +230,15 @@ for prepath in "$prepaths[@]"; do if [[ -n "$PREFIX$SUFFIX" ]]; then # See which of them match what's on the line. - compadd -O tmp2 "$ignore[@]" - "${(@)tmp1##*/}" + tmp2=("$tmp1[@]") + compadd -D tmp1 "$ignore[@]" - "${(@)tmp1##*/}" # If no file matches, save the expanded path and continue with # the outer loop. - if [[ $#tmp2 -eq 0 ]]; then - if [[ "$tmp1[1]" = */* ]]; then - tmp2=( "${(@)tmp1#${prepath}${realpath}}" ) + if [[ $#tmp1 -eq 0 ]]; then + if [[ "$tmp2[1]" = */* ]]; then + tmp2=( "${(@)tmp2#${prepath}${realpath}}" ) if [[ "$tmp2[1]" = */* ]]; then exppaths=( "$exppaths[@]" ${^tmp2%/*}/${tpre}${tsuf} ) else @@ -246,14 +247,6 @@ for prepath in "$prepaths[@]"; do fi continue 2 fi - - # Remove all files that weren't matched. - - if [[ "$tmp1[1]" = */* ]]; then - tmp1=( "${(@M)tmp1:#*/(${(j:|:)~${(@)tmp2:q}})}" ) - else - tmp1=( "${(@M)tmp1:#(${(j:|:)~${(@)tmp2:q}})}" ) - fi elif (( ! $#tmp1 )); then continue 2 fi diff --git a/Completion/Core/compinstall b/Completion/Core/compinstall new file mode 100644 index 000000000..d96121cf2 --- /dev/null +++ b/Completion/Core/compinstall @@ -0,0 +1,216 @@ +# This script is to be run by a user to setup the new function based +# completion system. The functions themselves are assumed to be already +# available in some directory; they should have been installed with the +# the shell (except we haven't written that yet). +# +# Run it as a script under zsh and answer the questions. +# You can run it as `zsh compinstall $FPATH' and it will be able to check +# your function path for the completion functions. +# +# Normally, this will alter ~/.zshrc (or wherever ZDOTDIR puts it), +# but you can make that unwritable and it will leave the lines in a +# temporary file instead. +# +# You can use this script to modify what compinstall previously +# added to ~/.zshrc. +# +# It is safe to abort with ^C any time you are being prompted for +# information; your .zshrc will not be altered. +# +# To do: +# - Maybe this should be sourced, then it can check the user's current +# setup better. But then there is a potentially horrendous option +# setting/resetting problem. (Maybe we need another way of doing that.) +# - Should probably offer to set different options for _approximate than +# for _complete if both are used. +# - Could add code for setting other completers and options. +# - Could add keys for context-sensitive help. +# - Probably should allow a set of directories to be added to $fpath, +# like Core, Base, etc. + +# In case a startup script changed options +emulate zsh + +[[ -n $1 ]] && FPATH=$1 + +for f in $fpath; do + if [[ $f != . && -f $f/compinit && -f $f/compdump ]]; then + fdir=$f + break + fi +done + +if [[ -z $fdir ]]; then + print "Trying to find where the completion functions are..." + if [[ $0 = */* && -f $0:h/compinit && -f $0:h/compdump ]]; then + fdir=$0:h + else + # more guesses? + print \ +"Please edit the name of the directory where the completion functions are +installed. If they are not installed, you will need to find them in the +Completion/* directories of the zsh distribution and install them yourself, +or insult your system manager for incompetence." + vared -c fdir + while [[ ! -d ${~fdir} || ! -f ${~fdir}/compinit || + ! -f ${~fdir}/compdump ]]; do + print "I can't find them in that directory. Try again or abort." + vared fdir + done + fi + eval "fpath=($fdir \$fpath)" + fdir=${fdir/#$HOME/\~} + lines="fpath=($fdir \$fpath)\n" +else + print "Found completion functions in your fpath, will not alter it." +fi + +files=( ${^~fpath:/.}/_(|*[^~])(N:t) ) +if [[ $#files -lt 20 ]]; then + print " +Hmmm, completion functions seem a bit thin on the ground. There should +be lots of files with names beginning with an underscore (_). You should +look and see what's happened to these. +[Hit return to continue]" + read +fi + +if [[ -w ${~fdir} && ( ! -f ${~fdir}/compinit.dump || + -w ${~fdir}/compinit.dump ) ]] +then + print " +Using standard dumpfile + ${~fdir}/compinit.dump +to speed up initialisation. +[Hit return to continue]" + read +else + print " +I will force completion to dump its status, which will speed up the shell's +start-up considerably. However, I can't write the file I'd like to, namely +$fdir/compinit.dump. Please edit a replacement." + dumpfile='~/.compinit.dump' + vared dumpfile + while ! touch ${~dumpfile} >& /dev/null; do + print "Sorry, I can't write that either. Try again." + vared dumpfile + done + [[ -s $dumpfile ]] || rm -f $dumpfile + dumpfile=" $dumpfile" +fi + +fdir=${fdir/#$HOME/\~} + +lines="${lines}. $fdir/compinit -d$dumpfile\n" + + +print " +In addition to completion, zsh can also perform correction of the +current word, or approximate completion, i.e. completion where the part of +the word typed so far can be corrected; or it can try correction, then +approximate completion if that fails. Would you like: + 0: Just ordinary completion + C: Correction + A: Approximate completion + B: Both? +Please type one of the keys above:" +while read -k type; do + print + case $type in + 0*) completer=_complete + break + ;; + [cC]*) completer=_complete:_correct + break + ;; + [aA]*) completer=_complete:_approximate + break; + ;; + [bB]*) completer=_complete:_correct:_approximate + break + ;; + *) print Try again + ;; + esac +done + +lines="${lines}compconf completer=$completer" + + +if [[ $completer = *(correct|approx)* ]]; then + print " +Correction and approximation will normally allow up to two errors, +and you will be able to use a numeric prefix (e.g. 4) to allow +more. The standard prompt is \`correct to:'. Do you want to change +any of this? [n]" + if read -q; then + print "Number of errors to accept normally (0 is OK):" + read accept + while [[ $accept != <-> ]]; do + read accept"?Please enter a number: " + done + print \ +"How would you like the numeric prefix to be treated: + 0: Not used by correction + U: Used to given the number of errors + I: If present, and not 1, do not perform correction? +Please type one of the keys above:" + while read -k type; do + print + case $type in + 0*) break + ;; + [uU]*) accept="${accept}n" + break + ;; + [Ii]*) accept="${accept}!n" + break + ;; + *) print Try again + ;; + esac + done + lines="$lines \\\\ + correct_accept='$accept'" + print " +Instead of the prompt \`correct to:', you can have no prompt, or a +prompt of your choosing which can display the number of errors found by +containing the string \`%e'. Do you wish to change the correction +prompt? [n]" + if read -q; then + cprompt='' + print "Edit a new prompt (may be empty):" + vared cprompt + lines="$lines \\\\ + correct_prompt='${cprompt//\'/\'\\\'\'}'" + fi + fi +fi + +lines="$lines\n" + + +startline='# The following lines were added by compinstall' +endline='# End of lines added by compinstall' + +ifile=${ZDOTDIR:-~}/.zshrc +[[ -f $ifile ]] || touch $ifile +tmpf=${TMPPPREFIX:-/tmp/zsh}compinstall$$ + +if [[ ! -w $ifile ]]; then + print "\nI can't write to $ifile. I will leave the lines to add in +\`$tmpf' and you must add them by hand." + print "\n$startline\n$lines\n$endline" >$tmpf + return 0 +fi + +if grep $endline $ifile >& /dev/null; then + print -- "$startline\n$lines$endline" >$tmpf + sed -e "/^$endline/r $tmpf +/^$startline/,/^$endline/d" $ifile >${tmpf}2 && mv ${tmpf}2 $ifile && + print "\nSuccesfully modified old compinstall lines in $ifile." + rm -f $tmpf ${tmpf}2 +else + print "\n$startline\n$lines\n$endline" >>$ifile && + print "\nSuccessfully appended lines to $ifile." +fi diff --git a/Completion/User/_make b/Completion/User/_make index acaa56b8e..a30ca4b7a 100644 --- a/Completion/User/_make +++ b/Completion/User/_make @@ -1,3 +1,3 @@ #compdef make gmake pmake -compgen -s "\$(awk '/^[a-zA-Z0-9][^\/ ]+:/ {print \$1}' FS=: [mM]akefile /dev/null)" +compgen -s "\$(awk '/^[a-zA-Z0-9][^\/ ]+:/ {print \$1}' FS=: [mM]akefile /dev/null)" -- cgit 1.4.1