From 904b939cbd81a542303da2c58288b95b153106f5 Mon Sep 17 00:00:00 2001 From: Tanaka Akira Date: Thu, 15 Apr 1999 18:17:36 +0000 Subject: zsh-3.1.5-pws-10 --- Completion/Base/_command_names | 3 + Completion/Base/_condition | 10 ++ Completion/Base/_default | 13 ++ Completion/Base/_match_pattern | 31 ++++ Completion/Base/_match_test | 15 ++ Completion/Base/_precommand | 5 + Completion/Base/_redirect | 3 + Completion/Base/_subscript | 4 + Completion/Base/_vars | 3 + Completion/Builtins/_aliases | 3 + Completion/Builtins/_arrays | 3 + Completion/Builtins/_autoload | 3 + Completion/Builtins/_bg_jobs | 3 + Completion/Builtins/_bindkey | 7 + Completion/Builtins/_builtin | 7 + Completion/Builtins/_cd | 3 + Completion/Builtins/_command | 7 + Completion/Builtins/_dirs | 3 + Completion/Builtins/_disable | 6 + Completion/Builtins/_echotc | 3 + Completion/Builtins/_enable | 6 + Completion/Builtins/_fc | 7 + Completion/Builtins/_functions | 3 + Completion/Builtins/_hash | 13 ++ Completion/Builtins/_jobs | 3 + Completion/Builtins/_kill | 11 ++ Completion/Builtins/_limits | 3 + Completion/Builtins/_sched | 3 + Completion/Builtins/_set | 7 + Completion/Builtins/_setopt | 7 + Completion/Builtins/_source | 7 + Completion/Builtins/_trap | 7 + Completion/Builtins/_unhash | 6 + Completion/Builtins/_unsetopt | 7 + Completion/Builtins/_vars_eq | 3 + Completion/Builtins/_wait | 7 + Completion/Builtins/_which | 3 + Completion/Builtins/_zftp | 50 ++++++ Completion/Builtins/_zle | 7 + Completion/Builtins/_zmodload | 9 + Completion/Commands/_correct_filename | 37 ++++ Completion/Commands/_most_recent_file | 4 + Completion/Core/_comp_parts | 147 ++++++++++++++++ Completion/Core/_compalso | 13 ++ Completion/Core/_files | 26 +++ Completion/Core/_main_complete | 48 ++++++ Completion/Core/_normal | 54 ++++++ Completion/Core/_path_files | 311 ++++++++++++++++++++++++++++++++++ Completion/Core/compdump | 89 ++++++++++ Completion/Core/compinit | 269 +++++++++++++++++++++++++++++ Completion/README | 107 ++++++++++++ Completion/User/_a2ps | 22 +++ Completion/User/_compress | 3 + Completion/User/_configure | 12 ++ Completion/User/_dd | 13 ++ Completion/User/_dvi | 3 + Completion/User/_find | 21 +++ Completion/User/_gunzip | 3 + Completion/User/_gzip | 3 + Completion/User/_hosts | 3 + Completion/User/_make | 3 + Completion/User/_man | 11 ++ Completion/User/_mh | 70 ++++++++ Completion/User/_pdf | 3 + Completion/User/_ps | 3 + Completion/User/_rcs | 9 + Completion/User/_rlogin | 9 + Completion/User/_strip | 2 + Completion/User/_stty | 16 ++ Completion/User/_tar | 11 ++ Completion/User/_tex | 3 + Completion/User/_uncompress | 3 + Completion/User/_x_options | 5 + Completion/User/_xfig | 3 + 74 files changed, 1643 insertions(+) create mode 100644 Completion/Base/_command_names create mode 100644 Completion/Base/_condition create mode 100644 Completion/Base/_default create mode 100644 Completion/Base/_match_pattern create mode 100644 Completion/Base/_match_test create mode 100644 Completion/Base/_precommand create mode 100644 Completion/Base/_redirect create mode 100644 Completion/Base/_subscript create mode 100644 Completion/Base/_vars create mode 100644 Completion/Builtins/_aliases create mode 100644 Completion/Builtins/_arrays create mode 100644 Completion/Builtins/_autoload create mode 100644 Completion/Builtins/_bg_jobs create mode 100644 Completion/Builtins/_bindkey create mode 100644 Completion/Builtins/_builtin create mode 100644 Completion/Builtins/_cd create mode 100644 Completion/Builtins/_command create mode 100644 Completion/Builtins/_dirs create mode 100644 Completion/Builtins/_disable create mode 100644 Completion/Builtins/_echotc create mode 100644 Completion/Builtins/_enable create mode 100644 Completion/Builtins/_fc create mode 100644 Completion/Builtins/_functions create mode 100644 Completion/Builtins/_hash create mode 100644 Completion/Builtins/_jobs create mode 100644 Completion/Builtins/_kill create mode 100644 Completion/Builtins/_limits create mode 100644 Completion/Builtins/_sched create mode 100644 Completion/Builtins/_set create mode 100644 Completion/Builtins/_setopt create mode 100644 Completion/Builtins/_source create mode 100644 Completion/Builtins/_trap create mode 100644 Completion/Builtins/_unhash create mode 100644 Completion/Builtins/_unsetopt create mode 100644 Completion/Builtins/_vars_eq create mode 100644 Completion/Builtins/_wait create mode 100644 Completion/Builtins/_which create mode 100644 Completion/Builtins/_zftp create mode 100644 Completion/Builtins/_zle create mode 100644 Completion/Builtins/_zmodload create mode 100644 Completion/Commands/_correct_filename create mode 100644 Completion/Commands/_most_recent_file create mode 100644 Completion/Core/_comp_parts create mode 100644 Completion/Core/_compalso create mode 100644 Completion/Core/_files create mode 100644 Completion/Core/_main_complete create mode 100644 Completion/Core/_normal create mode 100644 Completion/Core/_path_files create mode 100644 Completion/Core/compdump create mode 100644 Completion/Core/compinit create mode 100644 Completion/README create mode 100644 Completion/User/_a2ps create mode 100644 Completion/User/_compress create mode 100644 Completion/User/_configure create mode 100644 Completion/User/_dd create mode 100644 Completion/User/_dvi create mode 100644 Completion/User/_find create mode 100644 Completion/User/_gunzip create mode 100644 Completion/User/_gzip create mode 100644 Completion/User/_hosts create mode 100644 Completion/User/_make create mode 100644 Completion/User/_man create mode 100644 Completion/User/_mh create mode 100644 Completion/User/_pdf create mode 100644 Completion/User/_ps create mode 100644 Completion/User/_rcs create mode 100644 Completion/User/_rlogin create mode 100644 Completion/User/_strip create mode 100644 Completion/User/_stty create mode 100644 Completion/User/_tar create mode 100644 Completion/User/_tex create mode 100644 Completion/User/_uncompress create mode 100644 Completion/User/_x_options create mode 100644 Completion/User/_xfig (limited to 'Completion') diff --git a/Completion/Base/_command_names b/Completion/Base/_command_names new file mode 100644 index 000000000..d3b8a109a --- /dev/null +++ b/Completion/Base/_command_names @@ -0,0 +1,3 @@ +#defcomp -command- + +complist -c diff --git a/Completion/Base/_condition b/Completion/Base/_condition new file mode 100644 index 000000000..3e45e1b8f --- /dev/null +++ b/Completion/Base/_condition @@ -0,0 +1,10 @@ +#defcomp -condition- + +if [[ -current -1 -o ]]; then + complist -o -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' +elif [[ -current -1 -nt || -current -1 -ot || -current -1 -ef ]]; then + _files +else + _files + complist -v +fi diff --git a/Completion/Base/_default b/Completion/Base/_default new file mode 100644 index 000000000..8bcf14f6a --- /dev/null +++ b/Completion/Base/_default @@ -0,0 +1,13 @@ +#defcomp -default- + +# We first try the `compctl's. This is without first (-T) and default (-D) +# completion. If you want them add `-T' and/or `-D' to this command. +# If there is a `compctl' for the command we are working on, we return +# immediatly. If you want to use new style completion anyway, remove the +# `|| return'. Also, you may want to use new style completion if the +# `compctl' didn't produce any matches. In that case remove the `|| return' +# and at the line `[[ -nmatches 0 ]] || return' after `compcall'. + +compcall || return + +_files diff --git a/Completion/Base/_match_pattern b/Completion/Base/_match_pattern new file mode 100644 index 000000000..c5debc0b9 --- /dev/null +++ b/Completion/Base/_match_pattern @@ -0,0 +1,31 @@ +#autoload + +# This function is called from functions that do matching whenever they +# need to build a pattern that is used to match possible completions. +# It gets the name of the calling function and two names of parameters +# as arguments. The first one is used in the calling function to build +# the pattern used for matching possible completions. The content of this +# parameter on entry to this function is the string taken from the line. +# Here it parameter should be changed to a pattern that matches words as +# the match specs currently in use do. +# In the calling function this pattern may be changed again or used only +# in parts. The second parameter whose name is given as the third argument +# allows to give pattern flags liek `(#l)' that are to be used whenever +# matching is done. +# +# As an example, if you have global match specifications like: +# +# compctl -M 'm:{a-z}={A-Z}' 'm:{a-z}={A-Z} r:|[.-]=* r:|=*' +# +# This function would look like: +# +# eval "${3}='(#l)'" +# [[ MATCHER -eq 2 ]] && eval "$1='${(P)2:gs/./*./:gs/-/*-/}'" +# +# The first line makes sure that matching is done case-insensitive as +# specified by `m:{a-z}={A-Z}'. The second line replaces dots and hyphens +# in the given string by patterns matching any characters before them, +# like the `r:|[.-]=* r:|=*'. To make this work, the function `_match_test' +# would have to be changed to `(( MATCHERS <= 2 ))' +# +# The default implementation of this function is empty. diff --git a/Completion/Base/_match_test b/Completion/Base/_match_test new file mode 100644 index 000000000..e8b6e6424 --- /dev/null +++ b/Completion/Base/_match_test @@ -0,0 +1,15 @@ +#autoload + +# This function is called at the beginning of functions that do matching in +# shell code. It should test the value of the `MATCHER' special parameter +# and return non-zero if the calling function should try to generate matches +# for the global match specification in use. +# +# This function gets one argument, the name of the function calling it. +# +# If you have a global match specification with more than one set of patterns +# you may want to modify this function to return non-zero for all of your +# match specifications and modify the function `_match_pattern' to build the +# pattern to use in the calling function. + +(( MATCHER == 1 )) diff --git a/Completion/Base/_precommand b/Completion/Base/_precommand new file mode 100644 index 000000000..2cf661147 --- /dev/null +++ b/Completion/Base/_precommand @@ -0,0 +1,5 @@ +#defcomp - nohup nice eval time rusage noglob nocorrect exec + +[[ -position 1 -1 ]] + +_normal "$@" diff --git a/Completion/Base/_redirect b/Completion/Base/_redirect new file mode 100644 index 000000000..32113ad7c --- /dev/null +++ b/Completion/Base/_redirect @@ -0,0 +1,3 @@ +#defcomp -redirect- + +_files diff --git a/Completion/Base/_subscript b/Completion/Base/_subscript new file mode 100644 index 000000000..2b827a117 --- /dev/null +++ b/Completion/Base/_subscript @@ -0,0 +1,4 @@ +#defcomp -subscript- + +_compalso -math- "$@" +[[ ${(Pt)${COMMAND}} = assoc* ]] && complist -k "( ${(kP)${COMMAND}} )" diff --git a/Completion/Base/_vars b/Completion/Base/_vars new file mode 100644 index 000000000..7153b6f38 --- /dev/null +++ b/Completion/Base/_vars @@ -0,0 +1,3 @@ +#defcomp -math- getopts read unset vared + +complist -v diff --git a/Completion/Builtins/_aliases b/Completion/Builtins/_aliases new file mode 100644 index 000000000..1038a726e --- /dev/null +++ b/Completion/Builtins/_aliases @@ -0,0 +1,3 @@ +#defcomp unalias + +complist -a diff --git a/Completion/Builtins/_arrays b/Completion/Builtins/_arrays new file mode 100644 index 000000000..cbeac7118 --- /dev/null +++ b/Completion/Builtins/_arrays @@ -0,0 +1,3 @@ +#defcomp shift + +complist -A diff --git a/Completion/Builtins/_autoload b/Completion/Builtins/_autoload new file mode 100644 index 000000000..4f506baeb --- /dev/null +++ b/Completion/Builtins/_autoload @@ -0,0 +1,3 @@ +#defcomp autoload + +complist -s '${^fpath}/*(N:t)' diff --git a/Completion/Builtins/_bg_jobs b/Completion/Builtins/_bg_jobs new file mode 100644 index 000000000..511bb8308 --- /dev/null +++ b/Completion/Builtins/_bg_jobs @@ -0,0 +1,3 @@ +#defcomp bg + +complist -z -P '%' diff --git a/Completion/Builtins/_bindkey b/Completion/Builtins/_bindkey new file mode 100644 index 000000000..8eddeb2a8 --- /dev/null +++ b/Completion/Builtins/_bindkey @@ -0,0 +1,7 @@ +#defcomp bindkey + +if [[ -mword 1 -*[DAN]* || -mcurrent -1 -*M ]]; then + complist -s '$(bindkey -l)' +else + complist -b +fi diff --git a/Completion/Builtins/_builtin b/Completion/Builtins/_builtin new file mode 100644 index 000000000..a967932ee --- /dev/null +++ b/Completion/Builtins/_builtin @@ -0,0 +1,7 @@ +#defcomp builtin + +if [[ -position 2 -1 ]]; then + _normal "$@" +else + complist -eB +fi diff --git a/Completion/Builtins/_cd b/Completion/Builtins/_cd new file mode 100644 index 000000000..f3ce67ec7 --- /dev/null +++ b/Completion/Builtins/_cd @@ -0,0 +1,3 @@ +#defcomp cd + +_files -W cdpath -g '*(-/)' diff --git a/Completion/Builtins/_command b/Completion/Builtins/_command new file mode 100644 index 000000000..b2812de25 --- /dev/null +++ b/Completion/Builtins/_command @@ -0,0 +1,7 @@ +#defcomp command + +if [[ -position 2 -1 ]]; then + _normal "$@" +else + complist -em +fi diff --git a/Completion/Builtins/_dirs b/Completion/Builtins/_dirs new file mode 100644 index 000000000..bc426e322 --- /dev/null +++ b/Completion/Builtins/_dirs @@ -0,0 +1,3 @@ +#defcomp rmdir df du dircmp + +_files -/ diff --git a/Completion/Builtins/_disable b/Completion/Builtins/_disable new file mode 100644 index 000000000..063b65a7d --- /dev/null +++ b/Completion/Builtins/_disable @@ -0,0 +1,6 @@ +#defcomp disable + +[[ -mcurrent -1 -*a* ]] && complist -ea +[[ -mcurrent -1 -*f* ]] && complist -eF +[[ -mcurrent -1 -*r* ]] && complist -ew +[[ ! -mcurrent -1 -* ]] && complist -eB diff --git a/Completion/Builtins/_echotc b/Completion/Builtins/_echotc new file mode 100644 index 000000000..85ebb97ce --- /dev/null +++ b/Completion/Builtins/_echotc @@ -0,0 +1,3 @@ +#defcomp echotc + +complist -k '(al dc dl do le up al bl cd ce cl cr dc dl do ho is le ma nd nl se so up)' diff --git a/Completion/Builtins/_enable b/Completion/Builtins/_enable new file mode 100644 index 000000000..22ff53ee7 --- /dev/null +++ b/Completion/Builtins/_enable @@ -0,0 +1,6 @@ +#defcomp enable + +[[ -mcurrent -1 -*a* ]] && complist -da +[[ -mcurrent -1 -*f* ]] && complist -dF +[[ -mcurrent -1 -*r* ]] && complist -dw +[[ ! -mcurrent -1 -* ]] && complist -dB diff --git a/Completion/Builtins/_fc b/Completion/Builtins/_fc new file mode 100644 index 000000000..f0d2c03fd --- /dev/null +++ b/Completion/Builtins/_fc @@ -0,0 +1,7 @@ +#defcomp fc + +if [[ -mcurrent -1 -*e ]]; then + complist -c +elif [[ -mcurrent -1 -[ARWI]## ]]; then + _files +fi diff --git a/Completion/Builtins/_functions b/Completion/Builtins/_functions new file mode 100644 index 000000000..8a352ea08 --- /dev/null +++ b/Completion/Builtins/_functions @@ -0,0 +1,3 @@ +#defcomp unfunction + +complist -F diff --git a/Completion/Builtins/_hash b/Completion/Builtins/_hash new file mode 100644 index 000000000..171c5e2e8 --- /dev/null +++ b/Completion/Builtins/_hash @@ -0,0 +1,13 @@ +#defcomp hash + +if [[ -mword 1 -*d* ]]; then + if [[ -string 1 '=' ]]; then + _path_files -g '*(-/)' + else + complist -n -q -S '=' + fi +elif [[ -string 1 '=' ]]; then + _files -/g '*(*)' +else + complist -m -q -S '=' +fi diff --git a/Completion/Builtins/_jobs b/Completion/Builtins/_jobs new file mode 100644 index 000000000..018883c61 --- /dev/null +++ b/Completion/Builtins/_jobs @@ -0,0 +1,3 @@ +#defcomp fg jobs + +complist -j -P '%' diff --git a/Completion/Builtins/_kill b/Completion/Builtins/_kill new file mode 100644 index 000000000..50796d36f --- /dev/null +++ b/Completion/Builtins/_kill @@ -0,0 +1,11 @@ +#defcomp kill + +local list + +if [[ -iprefix '-' ]]; then + complist -k "($signals[1,-3])" +else + complist -P '%' -j + list=("$(ps 2>/dev/null)") + complist -y '$list' -s '`ps 2>/dev/null | tail +2 | cut -c1-5`' +fi diff --git a/Completion/Builtins/_limits b/Completion/Builtins/_limits new file mode 100644 index 000000000..35ccbe07e --- /dev/null +++ b/Completion/Builtins/_limits @@ -0,0 +1,3 @@ +#defcomp limit unlimit + +complist -k "(${(j: :)${(f)$(limit)}%% *})" diff --git a/Completion/Builtins/_sched b/Completion/Builtins/_sched new file mode 100644 index 000000000..1e8ae3445 --- /dev/null +++ b/Completion/Builtins/_sched @@ -0,0 +1,3 @@ +#defcomp sched + +[[ -position 2 -1 ]] && _normal "$@" diff --git a/Completion/Builtins/_set b/Completion/Builtins/_set new file mode 100644 index 000000000..5597025bc --- /dev/null +++ b/Completion/Builtins/_set @@ -0,0 +1,7 @@ +#defcomp set + +if [[ -mcurrent -1 [-+]o ]]; then + complist -o +elif [[ -current -1 -A ]]; then + complist -A +fi diff --git a/Completion/Builtins/_setopt b/Completion/Builtins/_setopt new file mode 100644 index 000000000..4abb3ccee --- /dev/null +++ b/Completion/Builtins/_setopt @@ -0,0 +1,7 @@ +#defcomp setopt + +local nm=$NMATCHES + +complist -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' \ + -s '$({ unsetopt kshoptionprint; unsetopt } 2>/dev/null)' +[[ -nmatches nm ]] && complist -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' -o diff --git a/Completion/Builtins/_source b/Completion/Builtins/_source new file mode 100644 index 000000000..aae2c7320 --- /dev/null +++ b/Completion/Builtins/_source @@ -0,0 +1,7 @@ +#defcomp source + +if [[ -position 2 -1 ]]; then + _normal "$@" +else + _files +fi diff --git a/Completion/Builtins/_trap b/Completion/Builtins/_trap new file mode 100644 index 000000000..59e81c589 --- /dev/null +++ b/Completion/Builtins/_trap @@ -0,0 +1,7 @@ +#defcomp trap + +if [[ -position 1 ]]; then + complist -c +else + complist -k signals +fi diff --git a/Completion/Builtins/_unhash b/Completion/Builtins/_unhash new file mode 100644 index 000000000..fe40c25a2 --- /dev/null +++ b/Completion/Builtins/_unhash @@ -0,0 +1,6 @@ +#defcomp unhash + +[[ -mword 1 -*d* ]] && complist -n +[[ -mword 1 -*a* ]] && complist -a +[[ -mword 1 -*f* ]] && complist -F +[[ ! -mword 1 -* ]] && complist -m diff --git a/Completion/Builtins/_unsetopt b/Completion/Builtins/_unsetopt new file mode 100644 index 000000000..90d642b51 --- /dev/null +++ b/Completion/Builtins/_unsetopt @@ -0,0 +1,7 @@ +#defcomp unsetopt + +local nm=$NMATCHES + +complist -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' \ + -s '$({ unsetopt kshoptionprint; setopt } 2>/dev/null)' +[[ -nmatches nm ]] && complist -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' -o diff --git a/Completion/Builtins/_vars_eq b/Completion/Builtins/_vars_eq new file mode 100644 index 000000000..fcbb0148c --- /dev/null +++ b/Completion/Builtins/_vars_eq @@ -0,0 +1,3 @@ +#defcomp declare export integer local readonly typeset + +complist -v -q -S '=' diff --git a/Completion/Builtins/_wait b/Completion/Builtins/_wait new file mode 100644 index 000000000..29a7f6002 --- /dev/null +++ b/Completion/Builtins/_wait @@ -0,0 +1,7 @@ +#defcomp wait + +local list + +complist -P '%' -j +list=("$(ps 2>/dev/null)") +complist -y '$list' -s '`ps 2>/dev/null | tail +2 | cut -c1-5`' diff --git a/Completion/Builtins/_which b/Completion/Builtins/_which new file mode 100644 index 000000000..324256e3d --- /dev/null +++ b/Completion/Builtins/_which @@ -0,0 +1,3 @@ +#defcomp which whence where type + +complist -caF diff --git a/Completion/Builtins/_zftp b/Completion/Builtins/_zftp new file mode 100644 index 000000000..9be9c94db --- /dev/null +++ b/Completion/Builtins/_zftp @@ -0,0 +1,50 @@ +#defpatcomp zf* + +# Don't try any more completion after this. +_compskip=1 + +# Completion for zftp builtin and zf* functions. The functions +# zfcd_match and zfget_match (used for old-style completion) +# need to be installed for remote file and directory completion to work. + +local subcom + +if [[ $COMMAND = zftp ]]; then + if [[ $CURRENT -eq 1 ]]; then + compadd -m open params user login type ascii binary mode put \ + putat get getat append appendat ls dir local remote mkdir rmdir + return + fi + subcom=$1 +else + subcom=$COMMAND +fi + +case $subcom in + *(cd|ls|dir)) + # complete remote directories; we could be smarter about hiding prefixes + zfcd_match $PREFIX $SUFFIX + (( $#reply )) && compadd -m -S/ -q $reply + ;; + + *(get(|at)|gcp|delete|remote)) + # complete remote files + zfget_match $PREFIX $SUFFIX + (( $#reply )) && compadd -F fignore -m $reply + ;; + + *(put(|at)|pcp)) + # complete local files + _files + ;; + + *(open|anon|params)) + # complete hosts: should do cleverer stuff with user names + complist -k hosts + ;; + + *) + # dunno... try ordinary completion after all. + unset _compskip + ;; +esac diff --git a/Completion/Builtins/_zle b/Completion/Builtins/_zle new file mode 100644 index 000000000..bb1102e74 --- /dev/null +++ b/Completion/Builtins/_zle @@ -0,0 +1,7 @@ +#defcomp zle + +if [[ -word 1 -N && -position 3 ]]; then + complist -F +else + complist -b +fi diff --git a/Completion/Builtins/_zmodload b/Completion/Builtins/_zmodload new file mode 100644 index 000000000..112acb57c --- /dev/null +++ b/Completion/Builtins/_zmodload @@ -0,0 +1,9 @@ +#defcomp zmodload + +if [[ -mword 1 -*(a*u|u*a)* || -mword 1 -*a* && -position 3 -1 ]]; then + complist -B +elif [[ -mword 1 -*u* ]]; then + complist -s '$(zmodload)' +else + complist -s '${^module_path}/*(N:t:r)' +fi diff --git a/Completion/Commands/_correct_filename b/Completion/Commands/_correct_filename new file mode 100644 index 000000000..edf1c65c2 --- /dev/null +++ b/Completion/Commands/_correct_filename @@ -0,0 +1,37 @@ +#defkeycomp complete-word \C-xc + +# Function to correct a filename. Can be used as a completion widget, +# or as a function in its own right, in which case it will print the +# corrected filename to standard output. +# +# You can adapt max_approx to the maximum number of mistakes +# which are allowed in total. + +emulate -LR zsh +setopt extendedglob + +local file="$PREFIX$SUFFIX" trylist +integer approx max_approx=6 + +[[ -z $WIDGET ]] && file=$1 + +if [[ -e "$file" ]]; then + if [[ -n $WIDGET ]]; then + compadd "$file" + else + print "$file" + fi + return +fi + +for (( approx = 1; approx <= max_approx; approx++ )); do + trylist=( (#a$approx)"$file"(N) ) + (( $#trylist )) && break +done +(( $#trylist )) || return 1 + +if [[ -n $WIDGET ]]; then + compadd -U "${trylist[@]}" +else + print "${trylist[@]}" +fi diff --git a/Completion/Commands/_most_recent_file b/Completion/Commands/_most_recent_file new file mode 100644 index 000000000..ff5645de5 --- /dev/null +++ b/Completion/Commands/_most_recent_file @@ -0,0 +1,4 @@ +#defkeycomp complete-word \C-xm +local file +file=($~PREFIX*$~SUFFIX(om[1]N)) +(( $#file )) && compadd -f $file diff --git a/Completion/Core/_comp_parts b/Completion/Core/_comp_parts new file mode 100644 index 000000000..7c24fd19d --- /dev/null +++ b/Completion/Core/_comp_parts @@ -0,0 +1,147 @@ +#autoload + +# This function can be used to separately complete parts of strings +# where each part may be one of a set of matches and different parts +# have different sets. +# Arguments are alternatingly arrays and separator strings. Arrays may +# be given by name or literally as words separated by white space in +# parentheses, e.g.: +# +# _comp_parts '(foo bar)' @ hosts +# +# This will make this function complete the strings in the array +# `friends'. If the string on the line contains a `@', the substring +# after it will be completed from the array `hosts'. Of course more +# arrays may be given, each preceded by another separator string. +# +# This function understands the `-J group', `-V group', and +# `-X explanation' options. +# +# This function does part of the matching itself and calls the functions +# `_match_test' and `_match_pattern' for this. + +local str arr sep test testarr tmparr prefix suffixes matchers autosuffix +local matchflags opt group expl + +# Test if we should use this function for the global matcher in use. + +_match_test _comp_parts || return + +# Get the options. + +group=() +expl=() +while getopts "J:V:X:" opt; do + case "$opt" in + [JV]) group=("-$opt" "$OPTARG");; + X) expl=(-X "$OPTARG");; + esac +done +shift OPTIND-1 + +# Get the string from the line. + +str="$PREFIX$SUFFIX" +prefix="" + +# Walk through the arguments to find the longest unambiguous prefix. + +while [[ $# -gt 1 ]]; do + # Get the next array and separator. + arr="$1" + sep="$2" + + if [[ "$arr[1]" == '(' ]]; then + tmparr=( ${=arr[2,-2]} ) + arr=tmparr + fi + # Is the separator on the line? + [[ "$str" != *${sep}* ]] && break + + # Build a pattern matching the possible matches and get all these + # matches in an array. + test="${str%%${sep}*}" + matchflags="" + _match_pattern _comp_parts test matchflags + test="${matchflags}${test}" + testarr=( "${(@M)${(@P)arr}:#${~test}*}" ) + + # If there are no matches we give up. If there is more than one + # match, this is the part we will complete. + (( $#testarr )) || return + [[ $#testarr -gt 1 ]] && break + + # Only one match, add it to the prefix and skip over it in `str', + # continuing with the next array and separator. + prefix="${prefix}${testarr[1]}${sep}" + str="${str#*${sep}}" + shift 2 +done + +# Get the array to work upon. +arr="$1" +if [[ "$arr[1]" == '(' ]]; then + tmparr=( ${=arr[2,-2]} ) + arr=tmparr +fi +if [[ $# -le 1 || "$str" != *${2}* ]]; then + # No more separators, build the matches. + matchflags="" + test="$str" + _match_pattern _comp_parts test matchflags + test="${matchflags}${test}" + testarr=( "${(@M)${(@P)arr}:#${~test}*}" ) +fi + +[[ $#testarr -eq 0 || ${#testarr[1]} -eq 0 ]] && return + +# Now we build the suffixes to give to the completion code. +shift +matchers=() +suffixes=("") +autosuffix=() + +while [[ $# -gt 0 && "$str" == *${1}* ]]; do + # Remove anything up to the the suffix. + str="${str#*${1}}" + + # Again, we get the string from the line up to the next separator + # and build a pattern from it. + if [[ $# -gt 2 ]]; then + test="${str%%${3}*}" + else + test="$str" + fi + matchflags="" + _match_pattern _comp_parts test matchflags + test="${matchflags}${test}" + + # We incrementally add suffixes by appending to them the seperators + # and the strings from the next array that match the pattern we built. + + arr="$2" + if [[ "$arr[1]" == '(' ]]; then + tmparr=( ${=arr[2,-2]} ) + arr=tmparr + fi + suffixes=("${^suffixes[@]}${1}${(@M)^${(@P)arr}:#${~test}*}") + + # We want the completion code to generate the most specific suffix + # for us, so we collect matching specifications that allow partial + # word matching before the separators on the fly. + matchers=("$matchers[@]" "r:|${1}=*") + shift 2 +done + +# If we were given at least one more separator we make the completion +# code offer it by appending it as a autoremovable suffix. +(( $# )) && autosuffix=(-qS "$1") + +# If we have collected matching specifications, we build an array +# from it that can be used as arguments to `compadd'. +[[ $#matchers -gt 0 ]] && matchers=(-M "$matchers") + +# Add the matches for each of the suffixes. +for i in "$suffixes[@]"; do + compadd "$group[@]" "$expl[@]" "$matchers[@]" "$autosuffix[@]" -p "$prefix" -s "$i" - "$testarr[@]" +done diff --git a/Completion/Core/_compalso b/Completion/Core/_compalso new file mode 100644 index 000000000..23a40e2d0 --- /dev/null +++ b/Completion/Core/_compalso @@ -0,0 +1,13 @@ +#autoload + +# This searches $1 in the array for normal completions and calls the result. +# It is used to include completions for another command or special context +# into the list generated by the calling function. +# For example the function for `-subscript-' could call this as in +# `_compalso -math- "$@"' to get the completions that would be generated +# for a mathematical context. + +local tmp + +tmp="$_comps[$1]" +[[ -z "$tmp" ]] || "$tmp" "$@" diff --git a/Completion/Core/_files b/Completion/Core/_files new file mode 100644 index 000000000..d2cce35e7 --- /dev/null +++ b/Completion/Core/_files @@ -0,0 +1,26 @@ +#autoload + +# Utility function for completing files of a given type or any file. +# In many cases you will want to call this one instead of _path_files(). + +local nm=$NMATCHES + +_path_files "$@" + +if [[ $# -ne 0 && -nmatches nm ]]; then + local opt opts + + # We didn't get any matches for those types of files described by + # the `-g' or `-/' option. Now we try it again accepting all files. + # First we get those options that we have to use even if then. If + # we find out that the `-f' option was given, we already accepted + # all files and give up immediatly. + + opts=() + while getopts "P:S:W:F:J:V:X:f/g:" opt; do + [[ "$opt" = f ]] && return + [[ "$opt" = [PSWFJVX] ]] && opts=("$opts[@]" "-$opt" "$OPTARG") + done + + _path_files "$opts[@]" +fi diff --git a/Completion/Core/_main_complete b/Completion/Core/_main_complete new file mode 100644 index 000000000..c7f5a5a96 --- /dev/null +++ b/Completion/Core/_main_complete @@ -0,0 +1,48 @@ +#autoload + +# The main loop of the completion code. This is what is called when +# completion is attempted from the command line. +# The completion code gives us the special variables and the arguments +# from the command line are given as positional parameters. + +local comp name + +setopt localoptions nullglob rcexpandparam globdots +unsetopt markdirs globsubst shwordsplit nounset + +# An entry for `-first-' is the replacement for `compctl -T' +# Completion functions may set `_compskip' to any value to make the +# main loops stop calling other completion functions. + +comp="$_comps[-first-]" +if [[ ! -z "$comp" ]]; then + "$comp" "$@" + if (( $+_compskip )); then + unset _compskip + return + fi +fi + +# For arguments we use the `_normal function. + +if [[ $CONTEXT == argument || $CONTEXT == command ]]; then + _normal "$@" +else + # Let's see if we have a special completion definition for the other + # possible contexts. + + comp='' + + case $CONTEXT in + redirect) comp="$_comps[-redirect-]";; + math) comp="$_comps[-math-]";; + subscript) comp="$_comps[-subscript-]";; + value) comp="$_comps[-value-]";; + condition) comp="$_comps[-condition-]";; + esac + + # If not, we use default completion, if any. + + [[ -z "$comp" ]] && comp="$_comps[-default-]" + [[ -z "$comp" ]] || "$comp" "$@" +fi diff --git a/Completion/Core/_normal b/Completion/Core/_normal new file mode 100644 index 000000000..19da6d79b --- /dev/null +++ b/Completion/Core/_normal @@ -0,0 +1,54 @@ +#autoload + +local comp cmd1 cmd2 pat val name + +# Completing in command position? If not we set up `cmd1' and `cmd2' as +# two strings we have search in the completion definition arrays (e.g. +# a path and the last path name component). + +if [[ $CONTEXT == command ]]; then + comp="$_comps[-command-]" + [[ -z "$comp" ]] || "$comp" "$@" + return +elif [[ "$COMMAND[1]" == '=' ]]; then + eval cmd1\=$COMMAND + cmd2="$COMMAND[2,-1]" +elif [[ "$COMMAND" == */* ]]; then + cmd1="$COMMAND" + cmd2="${COMMAND:t}" +else + cmd1="$COMMAND" + eval cmd2=$(whence -p $COMMAND) +fi + +# See if there are any matching pattern completions. + +for i in "$_patcomps[@]"; do + pat="${i% *}" + val="${i#* }" + if [[ "$cmd1" == $~pat || "$cmd2" == $~pat ]]; then + "$val" "$@" + if (( $+_compskip )); then + unset _compskip + return + fi + fi +done + +# Now look up the two names in the normal completion array. + +name="$cmd1" +comp="$_comps[$cmd1]" + +if [[ -z "$comp" ]]; then + name="$cmd2" + comp="$_comps[$cmd2]" +fi + +# And generate the matches, probably using default completion. + +if [[ -z "$comp" ]]; then + name=-default- + comp="$_comps[-default-]" +fi +[[ -z "$comp" ]] || "$comp" "$@" diff --git a/Completion/Core/_path_files b/Completion/Core/_path_files new file mode 100644 index 000000000..83b6e8a09 --- /dev/null +++ b/Completion/Core/_path_files @@ -0,0 +1,311 @@ +#autoload + +# Utility function for in-path completion. +# Supported arguments are: `-f', `-/', `-g ', `-J ', +# `-V ', `-W paths', `-X explanation', and `-F '. All but +# the last have the same syntax and meaning as for `complist'. The +# `-F ' option may be used to give a list of suffixes either by +# giving the name of an array or literally by giving them in a string +# surrounded by parentheses. Files with one of the suffixes thus given +# are treated like files with one of the suffixes in the `fignore' array +# in normal completion. +# +# This function uses the helper functions `_match_test' and `_match_pattern'. + +# First see if we should generate matches for the global matcher in use. + +_match_test _path_files || return + +# Yes, so... + +local nm prepaths str linepath realpath donepath patstr prepath testpath rest +local tmp1 collect tmp2 suffixes i ignore matchflags opt group sopt pats gopt +local addpfx addsfx expl + +setopt localoptions nullglob rcexpandparam globdots extendedglob +unsetopt markdirs globsubst shwordsplit nounset + +prepaths=('') +ignore=() +group=() +sopt='-' +gopt='' +pats=() +addpfx=() +addsfx=() +expl=() + +# Get the options. + +while getopts "P:S:W:F:J:V:X:f/g:" opt; do + case "$opt" in + P) addpfx=(-P "$OPTARG") + ;; + S) addsfx=(-S "$OPTARG") + ;; + W) tmp1="$OPTARG" + if [[ "$tmp1[1]" = '(' ]]; then + prepaths=( ${^=tmp1[2,-2]}/ ) + else + prepaths=( ${(P)=${tmp1}} ) + (( ! $#prepaths )) && prepaths=( ${tmp1}/ ) + fi + (( ! $#prepaths )) && prepaths=( '' ) + ;; + F) tmp1="$OPTARG" + if [[ "$tmp1[1]" = '(' ]]; then + ignore=( ${^=tmp1[2,-2]}/ ) + else + ignore=( ${(P)${tmp1}} ) + fi + (( $#ignore )) && ignore=(-F "( $ignore )") + ;; + [JV]) group=("-$opt" "$OPTARG") + ;; + X) expl=(-X "$OPTARG") + ;; + f) sopt="${sopt}f" + pats=("$pats[@]" '*') + ;; + /) sopt="${sopt}/" + pats=("$pats[@]" '*(-/)') + ;; + g) gopt='-g' + pats=("$pats[@]" ${=OPTARG}) + ;; + esac +done + +# If we were given no file selection option, we behave as if we were given +# a `-f'. + +if [[ "$sopt" = - ]]; then + if [[ -z "$gopt" ]]; then + sopt='-f' + pats=('*') + else + unset sopt + fi +fi + +# str holds the whole string from the command line with a `*' between +# the prefix and the suffix. + +str="${PREFIX:q}*${SUFFIX:q}" + +# If the string began with a `~', the quoting turned this into `\~', +# remove the slash. + +[[ "$str" = \\\~* ]] && str="$str[2,-1]" + +# We will first try normal completion called with `complist', but only if we +# weren't given a `-F' option. + +if (( ! $#ignore )); then + # First build an array containing the `-W' option, if there is any and we + # want to use it. We don't want to use it if the string from the command line + # is a absolute path or relative to the current directory. + + if [[ -z "$tmp1[1]" || "$str[1]" = [~/] || "$str" = (.|..)/* ]]; then + tmp1=() + else + tmp1=(-W "( $prepaths )") + fi + + # Now call complist. + + nm=$NMATCHES + if [[ -z "$gopt" ]]; then + complist "$addpfx[@]" "$addsfx[@]" "$group[@]" "$expl[@]" "$tmp1[@]" $sopt + else + complist "$addpfx[@]" "$addsfx[@]" "$group[@]" "$expl[@]" "$tmp1[@]" $sopt -g "$pats" + fi + + # If this generated any matches, we don't want to do in-path completion. + + [[ -nmatches nm ]] || return + + # No `-F' option, so we want to use `fignore'. + + ignore=(-F fignore) +fi + +# Now let's have a closer look at the string to complete. + +if [[ "$str[1]" = \~ ]]; then + # It begins with `~', so remember anything before the first slash to be able + # to report it to the completion code. Also get an expanded version of it + # (in `realpath'), so that we can generate the matches. Then remove that + # prefix from the string to complete, set `donepath' to build the correct + # paths and make sure that the loop below is run only once with an empty + # prefix path by setting `prepaths'. + + linepath="${str%%/*}/" + eval realpath\=$linepath + str="${str#*/}" + donepath='' + prepaths=( '' ) +else + # If the string does not start with a `~' we don't remove a prefix from the + # string. + + liniepath='' + realpath='' + + if [[ "$str[1]" = / ]]; then + # If it is a absolut path name, we remove the first slash and put it in + # `donepath' meaning that we treat it as the path that was already handled. + # Also, we don't use the paths from `-W'. + + str="$str[2,-1]" + donepath='/' + prepaths=( '' ) + else + # The common case, we just use the string as it is, unless it begins with + # `./' or `../' in which case we don't use the paths from `-W'. + + [[ "$str" = (.|..)/* ]] && prepaths=( '' ) + donepath='' + fi +fi + +# First we skip over all pathname components in `str' which really exist in +# the file-system, so that `/usr/lib/l' doesn't offer you `lib' and +# `lib5'. Pathname components skipped this way are taken from `str' and added +# to `donepath'. + +while [[ "$str" = */* ]] do + [[ -e "$realpath$donepath${str%%/*}" ]] || break + donepath="$donepath${str%%/*}/" + str="${str#*/}" +done + +# Now build the glob pattern by calling `_match_pattern'. +patstr="$str" +matchflags="" +_match_pattern _path_files patstr matchflags + +# We almost expect the pattern to have changed `..' into `*.*.', `/.' into +# `/*.', and probably to contain two or more consecutive `*'s. Since these +# have special meaning for globbing, we remove them. But before that, we +# add the pattern for matching any characters before a slash. + +patstr="$patstr:gs-/-*/-:gs/*.*.//:gs-/*.-/.-:gs/**/*/" + +# Finally, generate the matches. First we loop over all the paths from `-W'. +# Note that in this loop `str' is used as a modifyable version of `patstr' +# and `testpath' is a modifyable version of `donepath'. + +for prepath in "$prepaths[@]"; do + str="$patstr" + testpath="$donepath" + + # The second loop tests the components of the path in `str' to get the + # possible matches. + + while [[ "$str" = */* ]] do + # `rest' is the pathname after the first slash that is left. In `tmp1' + # we get the globbing matches for the pathname component currently + # handled. + + rest="${str#*/}" + tmp1="${prepath}${realpath}${testpath}${~matchflags}${str%%/*}(-/)" + tmp1=( $~tmp1 ) + + if [[ $#tmp1 -eq 0 ]]; then + # If this didn't produce any matches, we don't need to test this path + # any further, so continue with the next `-W' path, if any. + + continue 2 + elif [[ $#tmp1 -gt 1 ]]; then + # If it produced more than one match, we want to remove those which + # don't have possible following pathname components matching the + # rest of the string we are completing. (The case with only one + # match is handled below.) + # In `collect' we will collect those of the produced pathnames that + # have a matching possible path-suffix. In `suffixes' we build an + # array containing strings build from the rest of the string to + # complete and the glob patterns we were given as arguments. + + collect=() + suffixes=( $rest$^pats ) + suffixes=( "${(@)suffixes:gs.**.*.}" ) + + # In the loop the prefixes from the `tmp1' array produced above and + # the suffixes we just built are used to produce possible matches + # via globbing. + + for i in $tmp1; do + tmp2=( ${~i}/${~matchflags}${~suffixes} ) + [[ $#tmp2 -ne 0 ]] && collect=( $collect $i ) + done + + # If this test showed that none of the matches from the glob in `tmp1' + # has a possible sub-path matching what's on the line, we give up and + # continue with the next `-W' path. + + if [[ $#collect -eq 0 ]]; then + continue 2 + elif [[ $#collect -ne 1 ]]; then + # If we have more than one possible match, this means that the + # pathname component currently handled is ambiguous, so we give + # it to the completion code. + # First we build the full path prefix in `tmp1'. + + tmp1="$prepath$realpath$testpath" + + # Now produce all matching pathnames in `collect'. + + collect=( ${~collect}/${~matchflags}${~suffixes} ) + + # And then remove the common path prefix from all these matches. + + collect=( ${collect#$tmp1} ) + + # Finally, we add all these matches with the common (unexpanded) + # pathprefix (the `-p' option), the path-prefix (the `-W' option) + # to allow the completion code to test file type, and the path- + # suffix (the `-s' option). We also tell the completion code that + # these are file names and that `fignore' should be used as usual + # (the `-f' and `-F' options). + + for i in $collect; do + compadd "$addpfx[@]" "$addsfx[@]" "$group[@]" "$expl[@]" -p "$linepath$testpath" -W "$tmp1" -s "/${i#*/}" -f "$ignore[@]" - "${i%%/*}" + done + + # We have just finished handling all the matches from above, so we + # can continue with the next `-W' path. + + continue 2 + fi + # We reach this point if only one of the path prefixes in `tmp1' + # has a existing path-suffix matching the string from the line. + # In this case we accept this match and continue with the next + # path-name component. + + tmp1=( "$collect[1]" ) + fi + # This is also reached if the first globbing produced only one match + # in this case we just continue with the next pathname component, too. + + tmp1="$tmp1[1]" + testpath="$testpath${tmp1##*/}/" + str="$rest" + done + + # We are here if all pathname components except the last one (which is still + # not tested) are unambiguous. So we add matches with the full path prefix, + # no path suffix, the `-W' we are currently handling, all the matches we + # can produce in this directory, if any. + + tmp1="$prepath$realpath$testpath" + suffixes=( $str$^pats ) + suffixes=( "${(@)suffixes:gs.**.*.}" ) + tmp2=( ${~tmp1}${~matchflags}${~suffixes} ) + if [[ $#tmp2 -eq 0 && "$sopt" = */* ]]; then + [[ "$testpath[-1]" = / ]] && testpath="$testpath[1,-2]" + compadd "$addpfx[@]" "$addsfx[@]" "$group[@]" "$expl[@]" -f - "$linepath$testpath" + else + compadd "$addpfx[@]" "$addsfx[@]" "$group[@]" "$expl[@]" -p "$linepath$testpath" -W "$prepath$realpath$testpath" -f "$ignore[@]" - ${(@)tmp2#$tmp1} + fi +done diff --git a/Completion/Core/compdump b/Completion/Core/compdump new file mode 100644 index 000000000..8be096f50 --- /dev/null +++ b/Completion/Core/compdump @@ -0,0 +1,89 @@ +# This is a file to be sourced to dump the definitions for new-style +# completion defined by 'compinit' in the same directory. The output +# should be directed into the "compinit.dump" in the same directory as +# compinit. If you rename init, just stick .dump onto the end of whatever +# you have called it and put it in the same directory. This is handled +# automatically if you invoke compinit with the option -d. +# +# You will need to update the dump every time you add a new completion. +# To do this, simply remove the .dump file, start a new shell, and +# create the .dump file as before. Again, compinit -d handles this +# automatically. +# +# It relies on KSH_ARRAYS not being set. + +# Print the number of files used for completion. This is used in compinit +# to see if auto-dump should re-dump the dump-file. + +_d_file=${COMPDUMP-${0:h}/compinit.dump} + +typeset -U _d_files +_d_files=( ${^~fpath}/_*~*~(N:t) ) + +print "#files: $#_d_files" > $_d_file + +unset _d_files + +# First dump the arrays _comps 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 + print -r - "'${_d_f//\'/'\\''}'" "'${_comps[$_d_f]//\'/'\\''}'" +done >> $_d_file +print ")" >> $_d_file + +print "\n_patcomps=(" >> $_d_file +for _d_f in "$_patcomps[@]"; do + print -r - "'${_d_f//\'/'\\''}'" +done >> $_d_file +print ")" >> $_d_file + +print >> $_d_file + +# Now dump the key bindings. We dump all bindings for zle widgets +# whose names start with a underscore. +# We need both the zle -C's and the bindkey's to recreate. + +_d_bks=() +zle -lL | + while read -rA _d_line; do + if [[ ${_d_line[5]} = _* ]]; then + print -r - ${_d_line} + _d_bks=($_d_bks ${_d_line[3]}) + fi + done >> $_d_file +bindkey | + while read -rA _d_line; do + if [[ ${_d_line[2]} = (${(j.|.)~_d_bks}) ]]; then + print -r "bindkey '${_d_line[1][2,-2]}' ${_d_line[2]}" + fi + done >> $_d_file + +print >> $_d_file + + +# Autoloads: whence -w produces "_d_foo: function", so look for +# all functions beginning with `_'. + +_d_als=($(whence -wm '_*' | sort | +while read -rA _d_line; do + [[ ${_d_line[2]} = function ]] && print -r - ${_d_line[1]%:} +done)) + +# print them out: about five to a line looks neat + +while (( $#_d_als )); do + print -n autoload + for (( _i = 0; _i < 5; _i++ )); do + if (( $#_d_als )); then + print -n " $_d_als[1]" + shift _d_als + fi + done + print +done >> $_d_file + +print >> $_d_file + +unset _d_line _d_zle _d_bks _d_als _d_f _f_file diff --git a/Completion/Core/compinit b/Completion/Core/compinit new file mode 100644 index 000000000..ec5867838 --- /dev/null +++ b/Completion/Core/compinit @@ -0,0 +1,269 @@ +# Initialisation for new style completion. This mainly contains some helper +# function and aliases. Everything else is split into different files in this +# directory that will automatically be made autoloaded (see the end of this +# file). +# The names of the files that will be considered for autoloading have to +# start with a underscores (like `_setopt). +# The first line of these files will be read and has to say what should be +# done with its contents: +# +# `#defcomp ' +# if the first line looks like this, the file is +# autoloaded as a function and that function will +# be called to generate the matches when completing +# for one of the commands whose is given +# +# `#defpatcomp ' +# this defines a function that should be called to generate +# matches for commands whose name matches ; note +# that only one pattern may be given +# +# `#defkeycomp