about summary refs log tree commit diff
path: root/Completion/Builtins
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>1999-04-15 18:18:42 +0000
committerTanaka Akira <akr@users.sourceforge.net>1999-04-15 18:18:42 +0000
commit7a0415cfd70a02b2280d27556c6c54cef1c86e1a (patch)
tree37a88a1c4611ee37f2a3209873fc9a34a2624587 /Completion/Builtins
parent904b939cbd81a542303da2c58288b95b153106f5 (diff)
downloadzsh-7a0415cfd70a02b2280d27556c6c54cef1c86e1a.tar.gz
zsh-7a0415cfd70a02b2280d27556c6c54cef1c86e1a.tar.xz
zsh-7a0415cfd70a02b2280d27556c6c54cef1c86e1a.zip
zsh-3.1.5-pws-11 zsh-3.1.5-pws-11
Diffstat (limited to 'Completion/Builtins')
-rw-r--r--Completion/Builtins/_aliases2
-rw-r--r--Completion/Builtins/_arrays2
-rw-r--r--Completion/Builtins/_autoload2
-rw-r--r--Completion/Builtins/_bg_jobs2
-rw-r--r--Completion/Builtins/_bindkey6
-rw-r--r--Completion/Builtins/_builtin8
-rw-r--r--Completion/Builtins/_cd63
-rw-r--r--Completion/Builtins/_command6
-rw-r--r--Completion/Builtins/_disable10
-rw-r--r--Completion/Builtins/_echotc2
-rw-r--r--Completion/Builtins/_enable10
-rw-r--r--Completion/Builtins/_fc8
-rw-r--r--Completion/Builtins/_functions2
-rw-r--r--Completion/Builtins/_hash6
-rw-r--r--Completion/Builtins/_jobs2
-rw-r--r--Completion/Builtins/_kill6
-rw-r--r--Completion/Builtins/_limits2
-rw-r--r--Completion/Builtins/_sched2
-rw-r--r--Completion/Builtins/_set10
-rw-r--r--Completion/Builtins/_setopt7
-rw-r--r--Completion/Builtins/_source4
-rw-r--r--Completion/Builtins/_trap6
-rw-r--r--Completion/Builtins/_unhash10
-rw-r--r--Completion/Builtins/_unsetopt7
-rw-r--r--Completion/Builtins/_vars_eq2
-rw-r--r--Completion/Builtins/_wait4
-rw-r--r--Completion/Builtins/_which2
-rw-r--r--Completion/Builtins/_zftp14
-rw-r--r--Completion/Builtins/_zle6
-rw-r--r--Completion/Builtins/_zmodload12
30 files changed, 150 insertions, 75 deletions
diff --git a/Completion/Builtins/_aliases b/Completion/Builtins/_aliases
index 1038a726e..2ccf18439 100644
--- a/Completion/Builtins/_aliases
+++ b/Completion/Builtins/_aliases
@@ -1,3 +1,3 @@
 #defcomp unalias
 
-complist -a
+compgen -a
diff --git a/Completion/Builtins/_arrays b/Completion/Builtins/_arrays
index cbeac7118..94401f28a 100644
--- a/Completion/Builtins/_arrays
+++ b/Completion/Builtins/_arrays
@@ -1,3 +1,3 @@
 #defcomp shift
 
-complist -A
+compgen -A
diff --git a/Completion/Builtins/_autoload b/Completion/Builtins/_autoload
index 4f506baeb..d1462e09a 100644
--- a/Completion/Builtins/_autoload
+++ b/Completion/Builtins/_autoload
@@ -1,3 +1,3 @@
 #defcomp autoload
 
-complist -s '${^fpath}/*(N:t)'
+compgen -s '${^fpath}/*(N:t)'
diff --git a/Completion/Builtins/_bg_jobs b/Completion/Builtins/_bg_jobs
index 511bb8308..4abee070c 100644
--- a/Completion/Builtins/_bg_jobs
+++ b/Completion/Builtins/_bg_jobs
@@ -1,3 +1,3 @@
 #defcomp bg
 
-complist -z -P '%'
+compgen -z -P '%'
diff --git a/Completion/Builtins/_bindkey b/Completion/Builtins/_bindkey
index 8eddeb2a8..d3d019492 100644
--- a/Completion/Builtins/_bindkey
+++ b/Completion/Builtins/_bindkey
@@ -1,7 +1,7 @@
 #defcomp bindkey
 
-if [[ -mword 1 -*[DAN]* || -mcurrent -1 -*M ]]; then
-  complist -s '$(bindkey -l)'
+if [[ "$words[2]" = -*[DAN]* || "$words[CURRENT-1] = -*M ]]; then
+  compgen -s '$(bindkey -l)'
 else
-  complist -b
+  compgen -b
 fi
diff --git a/Completion/Builtins/_builtin b/Completion/Builtins/_builtin
index a967932ee..bee67fe8f 100644
--- a/Completion/Builtins/_builtin
+++ b/Completion/Builtins/_builtin
@@ -1,7 +1,9 @@
 #defcomp builtin
 
-if [[ -position 2 -1 ]]; then
-  _normal "$@"
+if (( $CURRENT > 2 )); then
+  shift words
+  (( CURRENT -- ))
+  _normal
 else
-  complist -eB
+  compgen -eB
 fi
diff --git a/Completion/Builtins/_cd b/Completion/Builtins/_cd
index f3ce67ec7..65ce7f293 100644
--- a/Completion/Builtins/_cd
+++ b/Completion/Builtins/_cd
@@ -1,3 +1,62 @@
-#defcomp cd
+#defcomp cd pushd
 
-_files -W cdpath -g '*(-/)'
+# Handling of cd.
+#  - Normally just completes directories.  Uses cdpath if that's set
+#    and the string doesn't begin with ~, /, ./ or ../.
+#  - In the second argument to cd for the form `cd old new', completes
+#    possible `new' strings by examining `old' and $PWD.
+#  - After pushd - or pushd +, completes numbers, but the listing
+#    gives you the list of directories to complete.  This turns on
+#    menu-completion and lists the possibilities automatically, otherwise
+#    it's not a lot of use.  If you don't type the + or - it will
+#    complete directories as normal.
+
+local pushdminus
+[[ -o pushdminus ]] && pushdminus=1
+
+emulate -LR zsh
+setopt extendedglob
+
+if [[ -position 3 ]]; then
+  # cd old new: look for old in $PWD and see what can replace it
+  local rep
+  # Get possible completions using word in position 2
+  rep=(${~PWD/$words[2]/*}~$PWD(-/N))
+  # Now remove all the common parts of $PWD and the completions from this
+  rep=(${${rep#${PWD%%$words[2]*}}%${PWD#*$words[2]}})
+  (( $#rep )) && compadd $rep
+elif [[ $words[1] = pu* && $PREFIX = [-+]* ]]; then
+  # pushd: just complete the numbers, but show the full directory list with
+  # numbers.
+  # For - we do the same thing, but reverse the numbering (other
+  # way round if pushdminus is set).
+  # The test is for pu* because I have an alias pu since I'm too
+  # lazy to type pushd.
+  IPREFIX=$PREFIX[1]
+  PREFIX=$PREFIX[2,-1]
+  local list lines
+  # get the list of directories with their canonical number
+  lines="$(dirs -v)"
+  # turn the lines into an array, removing the current directory
+  list=(${${(f)lines}##0*})
+  if [[ ( $IPREFIX = - && -z $pushdminus ) ||
+        ( $IPREFIX = + && -n $pushdminus ) ]]; then
+    # reverse the numbering: it counts the last one as -0, which
+    # is a little strange.
+    integer tot i
+    for (( i = 1, tot = $#list-1; tot >= 0; i++, tot-- )); do
+      list[$i]="$tot${list[$i]##[0-9]#}"
+    done
+  fi
+  # make sure -y treats this as a single string
+  lines="${(F)list}"
+  # get the array of numbers only
+  list=(${list%%[ 	]*})
+  compgen -y '$lines' -Q -k list
+  [[ -z $compstate[list] ]] && compstate[list]=list
+  [[ -n $compstate[insert] ]] && compstat[insert]=menu
+elif [[ $PREFIX != (\~|/|./|../)* && $#cdpath -ne 0 ]]; then
+  _path_files -W cdpath -/
+else
+  _path_files -/
+fi
diff --git a/Completion/Builtins/_command b/Completion/Builtins/_command
index b2812de25..47eb0d667 100644
--- a/Completion/Builtins/_command
+++ b/Completion/Builtins/_command
@@ -1,7 +1,7 @@
 #defcomp command
 
-if [[ -position 2 -1 ]]; then
-  _normal "$@"
+if [[ -position 3 -1 ]]; then
+  _normal
 else
-  complist -em
+  compgen -em
 fi
diff --git a/Completion/Builtins/_disable b/Completion/Builtins/_disable
index 063b65a7d..e3edafe2b 100644
--- a/Completion/Builtins/_disable
+++ b/Completion/Builtins/_disable
@@ -1,6 +1,8 @@
 #defcomp disable
 
-[[ -mcurrent -1 -*a* ]] && complist -ea
-[[ -mcurrent -1 -*f* ]] && complist -eF
-[[ -mcurrent -1 -*r* ]] && complist -ew
-[[ ! -mcurrent -1 -* ]] && complist -eB
+local prev="$words[CURRENT-1]"
+
+[[ "$prev" = -*a* ]] && compgen -ea
+[[ "$prev" = -*f* ]] && compgen -eF
+[[ "$prev" = -*r* ]] && compgen -ew
+[[ "$prev" != -* ]] && compgen -eB
diff --git a/Completion/Builtins/_echotc b/Completion/Builtins/_echotc
index 85ebb97ce..135cabada 100644
--- a/Completion/Builtins/_echotc
+++ b/Completion/Builtins/_echotc
@@ -1,3 +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)'
+compgen -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
index 22ff53ee7..111d1ae26 100644
--- a/Completion/Builtins/_enable
+++ b/Completion/Builtins/_enable
@@ -1,6 +1,8 @@
 #defcomp enable
 
-[[ -mcurrent -1 -*a* ]] && complist -da
-[[ -mcurrent -1 -*f* ]] && complist -dF
-[[ -mcurrent -1 -*r* ]] && complist -dw
-[[ ! -mcurrent -1 -* ]] && complist -dB
+local prev="$words[CURRENT-1]"
+
+[[ "$prev" = -*a* ]] && compgen -da
+[[ "$prev" = -*f* ]] && compgen -dF
+[[ "$prev" = -*r* ]] && compgen -dw
+[[ "$prev" != -* ]] && compgen -dB
diff --git a/Completion/Builtins/_fc b/Completion/Builtins/_fc
index f0d2c03fd..f8cf4dde8 100644
--- a/Completion/Builtins/_fc
+++ b/Completion/Builtins/_fc
@@ -1,7 +1,9 @@
 #defcomp fc
 
-if [[ -mcurrent -1 -*e ]]; then
-  complist -c
-elif [[ -mcurrent -1 -[ARWI]## ]]; then
+local prev="$words[CURRENT-1]"
+
+if [[ "$prev" = -*e ]]; then
+  compgen -c
+elif [[ "$prev" = -[ARWI]## ]]; then
   _files
 fi
diff --git a/Completion/Builtins/_functions b/Completion/Builtins/_functions
index 8a352ea08..7e3174af5 100644
--- a/Completion/Builtins/_functions
+++ b/Completion/Builtins/_functions
@@ -1,3 +1,3 @@
 #defcomp unfunction
 
-complist -F
+compgen -F
diff --git a/Completion/Builtins/_hash b/Completion/Builtins/_hash
index 171c5e2e8..8c100b801 100644
--- a/Completion/Builtins/_hash
+++ b/Completion/Builtins/_hash
@@ -1,13 +1,13 @@
 #defcomp hash
 
-if [[ -mword 1 -*d* ]]; then
+if [[ "$words[2]" = -*d* ]]; then
   if [[ -string 1 '=' ]]; then
     _path_files -g '*(-/)'
   else
-    complist -n -q -S '='
+    compgen -n -q -S '='
   fi
 elif [[ -string 1 '=' ]]; then
   _files -/g '*(*)'
 else
-  complist -m -q -S '='
+  compgen -m -q -S '='
 fi
diff --git a/Completion/Builtins/_jobs b/Completion/Builtins/_jobs
index 018883c61..8f6991de0 100644
--- a/Completion/Builtins/_jobs
+++ b/Completion/Builtins/_jobs
@@ -1,3 +1,3 @@
 #defcomp fg jobs
 
-complist -j -P '%'
+compgen -j -P '%'
diff --git a/Completion/Builtins/_kill b/Completion/Builtins/_kill
index 50796d36f..c1afa78cb 100644
--- a/Completion/Builtins/_kill
+++ b/Completion/Builtins/_kill
@@ -3,9 +3,9 @@
 local list
 
 if [[ -iprefix '-' ]]; then
-  complist -k "($signals[1,-3])"
+  compgen -k "($signals[1,-3])"
 else
-  complist -P '%' -j
+  compgen -P '%' -j
   list=("$(ps 2>/dev/null)")
-  complist -y '$list' -s '`ps 2>/dev/null | tail +2 | cut -c1-5`'
+  compgen -y '$list' -s '`ps 2>/dev/null | tail +2 | cut -c1-5`'
 fi
diff --git a/Completion/Builtins/_limits b/Completion/Builtins/_limits
index 35ccbe07e..8b0b41c71 100644
--- a/Completion/Builtins/_limits
+++ b/Completion/Builtins/_limits
@@ -1,3 +1,3 @@
 #defcomp limit unlimit
 
-complist -k "(${(j: :)${(f)$(limit)}%% *})"
+compgen -k "(${(j: :)${(f)$(limit)}%% *})"
diff --git a/Completion/Builtins/_sched b/Completion/Builtins/_sched
index 1e8ae3445..62cdbb070 100644
--- a/Completion/Builtins/_sched
+++ b/Completion/Builtins/_sched
@@ -1,3 +1,3 @@
 #defcomp sched
 
-[[ -position 2 -1 ]] && _normal "$@"
+[[ -position 3 -1 ]] && _normal
diff --git a/Completion/Builtins/_set b/Completion/Builtins/_set
index 5597025bc..959dac75d 100644
--- a/Completion/Builtins/_set
+++ b/Completion/Builtins/_set
@@ -1,7 +1,9 @@
 #defcomp set
 
-if [[ -mcurrent -1 [-+]o ]]; then
-  complist -o
-elif [[ -current -1 -A ]]; then
-  complist -A
+local prev="$words[CURRENT-1]"
+
+if [[ "$prev" = [-+]o ]]; then
+  compgen -o
+elif [[ "$prev" = -A ]]; then
+  compgen -A
 fi
diff --git a/Completion/Builtins/_setopt b/Completion/Builtins/_setopt
index 4abb3ccee..98800152f 100644
--- a/Completion/Builtins/_setopt
+++ b/Completion/Builtins/_setopt
@@ -1,7 +1,8 @@
 #defcomp setopt
 
-local nm=$NMATCHES
+local nm=$compstate[nmatches]
 
-complist -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' \
+compgen -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
+[[ compstate[nmatches] -eq nm ]] &&
+    compgen -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' -o
diff --git a/Completion/Builtins/_source b/Completion/Builtins/_source
index aae2c7320..1bbbf15a4 100644
--- a/Completion/Builtins/_source
+++ b/Completion/Builtins/_source
@@ -1,7 +1,7 @@
 #defcomp source
 
-if [[ -position 2 -1 ]]; then
-  _normal "$@"
+if [[ -position 3 -1 ]]; then
+  _normal
 else
   _files
 fi
diff --git a/Completion/Builtins/_trap b/Completion/Builtins/_trap
index 59e81c589..36ab1f1a8 100644
--- a/Completion/Builtins/_trap
+++ b/Completion/Builtins/_trap
@@ -1,7 +1,7 @@
 #defcomp trap
 
-if [[ -position 1 ]]; then
-  complist -c
+if [[ CURRENT -eq 2 ]]; then
+  compgen -c
 else
-  complist -k signals
+  compgen -k signals
 fi
diff --git a/Completion/Builtins/_unhash b/Completion/Builtins/_unhash
index fe40c25a2..63d61c991 100644
--- a/Completion/Builtins/_unhash
+++ b/Completion/Builtins/_unhash
@@ -1,6 +1,8 @@
 #defcomp unhash
 
-[[ -mword 1 -*d* ]] && complist -n
-[[ -mword 1 -*a* ]] && complist -a
-[[ -mword 1 -*f* ]] && complist -F
-[[ ! -mword 1 -* ]] && complist -m
+local fl="$words[2]"
+
+[[ "$fl" = -*d* ]] && compgen -n
+[[ "$fl" = -*a* ]] && compgen -a
+[[ "$fl" = -*f* ]] && compgen -F
+[[ "$fl" != -* ]] && compgen -m
diff --git a/Completion/Builtins/_unsetopt b/Completion/Builtins/_unsetopt
index 90d642b51..a5c85b1ef 100644
--- a/Completion/Builtins/_unsetopt
+++ b/Completion/Builtins/_unsetopt
@@ -1,7 +1,8 @@
 #defcomp unsetopt
 
-local nm=$NMATCHES
+local nm=$compstate[nmatches]
 
-complist -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' \
+compgen -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
+[[ compstate[nmatches] -eq nm ]] &&
+    compgen -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' -o
diff --git a/Completion/Builtins/_vars_eq b/Completion/Builtins/_vars_eq
index fcbb0148c..9488cb7f9 100644
--- a/Completion/Builtins/_vars_eq
+++ b/Completion/Builtins/_vars_eq
@@ -1,3 +1,3 @@
 #defcomp declare export integer local readonly typeset
 
-complist -v -q -S '='
+compgen -v -q -S '='
diff --git a/Completion/Builtins/_wait b/Completion/Builtins/_wait
index 29a7f6002..6e3a4c3c9 100644
--- a/Completion/Builtins/_wait
+++ b/Completion/Builtins/_wait
@@ -2,6 +2,6 @@
 
 local list
 
-complist -P '%' -j
+compgen -P '%' -j
 list=("$(ps 2>/dev/null)")
-complist -y '$list' -s '`ps 2>/dev/null | tail +2 | cut -c1-5`'
+compgen -y '$list' -s '`ps 2>/dev/null | tail +2 | cut -c1-5`'
diff --git a/Completion/Builtins/_which b/Completion/Builtins/_which
index 324256e3d..9248f9c9f 100644
--- a/Completion/Builtins/_which
+++ b/Completion/Builtins/_which
@@ -1,3 +1,3 @@
 #defcomp which whence where type
 
-complist -caF
+compgen -caF
diff --git a/Completion/Builtins/_zftp b/Completion/Builtins/_zftp
index 9be9c94db..e93021acf 100644
--- a/Completion/Builtins/_zftp
+++ b/Completion/Builtins/_zftp
@@ -9,28 +9,28 @@ _compskip=1
 
 local subcom
 
-if [[ $COMMAND = zftp ]]; then
+if [[ $words[1] = zftp ]]; then
   if [[ $CURRENT -eq 1 ]]; then
-    compadd -m open params user login type ascii binary mode put \
+    compadd open params user login type ascii binary mode put \
       putat get getat append appendat ls dir local remote mkdir rmdir
     return
   fi
-  subcom=$1
+  subcom=$words[2]
 else
-  subcom=$COMMAND
+  subcom=$words[1]
 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
+   (( $#reply )) && compadd -S/ -q - $reply
    ;;
 
   *(get(|at)|gcp|delete|remote))
    # complete remote files
    zfget_match $PREFIX $SUFFIX
-   (( $#reply )) && compadd -F fignore -m $reply
+   (( $#reply )) && compadd -F fignore - $reply
    ;;
 
   *(put(|at)|pcp))
@@ -40,7 +40,7 @@ case $subcom in
 
   *(open|anon|params))
   # complete hosts:  should do cleverer stuff with user names
-  complist -k hosts
+  compgen -k hosts
   ;;
 
   *)
diff --git a/Completion/Builtins/_zle b/Completion/Builtins/_zle
index bb1102e74..0a9ad0a9e 100644
--- a/Completion/Builtins/_zle
+++ b/Completion/Builtins/_zle
@@ -1,7 +1,7 @@
 #defcomp zle
 
-if [[ -word 1 -N && -position 3 ]]; then
-  complist -F
+if [[ "$words[2]" = -N && CURRENT -eq 3 ]]; then
+  compgen -F
 else
-  complist -b
+  compgen -b
 fi
diff --git a/Completion/Builtins/_zmodload b/Completion/Builtins/_zmodload
index 112acb57c..4259adf06 100644
--- a/Completion/Builtins/_zmodload
+++ b/Completion/Builtins/_zmodload
@@ -1,9 +1,11 @@
 #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)'
+local fl="$words[2]"
+
+if [[ "$fl" = -*(a*u|u*a)* || "$fl" = -*a* && -position 4 -1 ]]; then
+  compgen -B
+elif [[ "$fl" = -*u* ]]; then
+  compgen -s '$(zmodload)'
 else
-  complist -s '${^module_path}/*(N:t:r)'
+  compgen -s '${^module_path}/*(N:t:r)'
 fi