about summary refs log tree commit diff
path: root/Completion/Builtins/_cd
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>1999-10-08 17:04:12 +0000
committerTanaka Akira <akr@users.sourceforge.net>1999-10-08 17:04:12 +0000
commitd9e72bbb60a8172921f2b3ac47bdeccce18ccab4 (patch)
tree3e5e48017519f3dbe4d9daacc8a8163b30d36ccd /Completion/Builtins/_cd
parent8e6689380c9ff94bc4cc29dd1a090a8066c67e21 (diff)
downloadzsh-d9e72bbb60a8172921f2b3ac47bdeccce18ccab4.tar.gz
zsh-d9e72bbb60a8172921f2b3ac47bdeccce18ccab4.tar.xz
zsh-d9e72bbb60a8172921f2b3ac47bdeccce18ccab4.zip
zsh-workers/8181
Diffstat (limited to 'Completion/Builtins/_cd')
-rw-r--r--Completion/Builtins/_cd17
1 files changed, 8 insertions, 9 deletions
diff --git a/Completion/Builtins/_cd b/Completion/Builtins/_cd
index d0ba62f2f..8872d6d80 100644
--- a/Completion/Builtins/_cd
+++ b/Completion/Builtins/_cd
@@ -34,28 +34,27 @@ elif [[ $PREFIX = [-+]* ]]; then
   # lazy to type pushd.
   IPREFIX=$PREFIX[1]
   PREFIX=$PREFIX[2,-1]
-  local list lines ret=1
+  local list lines revlines ret=1 i
 
   # get the list of directories with their canonical number
   # and turn the lines into an array, removing the current directory
   lines=( ${${(f)"$(dirs -v)"}##0*} )
   if [[ ( $IPREFIX = - && ! -o pushdminus ) ||
         ( $IPREFIX = + && -o pushdminus ) ]]; then
-    # reverse the numbering: it counts the last one as -0, which
-    # is a little strange.
-    integer tot i
-    for (( i = 1, tot = $#lines-1; i <= $#lines; i++, tot-- )); do
-      lines[$i]="$tot -- ${lines[$i]##[0-9]#[	 ]#}"
+    integer i
+    revlines=( $lines )
+    for (( i = 1; i <= $#lines; i++ )); do
+      lines[$i]="$((i-1)) -- ${revlines[-$i]##[0-9]#[	 ]#}"
     done
   else
-    for (( i = 1, tot = 1; i <= $#lines; i++, tot++ )); do
-      lines[$i]="$tot -- ${lines[$i]##[0-9]#[	 ]#}"
+    for (( i = 1; i <= $#lines; i++ )); do
+      lines[$i]="$i -- ${lines[$i]##[0-9]#[	 ]#}"
     done
   fi
   # get the array of numbers only
   list=(${lines%% *})
   _description expl 'directory stack index'
-  compadd "$expl[@]" -ld lines -Q - "$list[@]" && ret=0
+  compadd "$expl[@]" -ld lines -V dirs -Q - "$list[@]" && ret=0
   [[ -z $compstate[list] ]] && compstate[list]=list && ret=0
   [[ -n $compstate[insert] ]] && compstate[insert]=menu && ret=0