about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--Completion/Base/_tilde41
-rw-r--r--Completion/Builtins/_cd19
2 files changed, 31 insertions, 29 deletions
diff --git a/Completion/Base/_tilde b/Completion/Base/_tilde
index cab371216..b8d639074 100644
--- a/Completion/Base/_tilde
+++ b/Completion/Base/_tilde
@@ -7,7 +7,9 @@
 #   `(( compstate[nmatches] )) || compgen -nu -qS/'
 # below that.
 
-local d c s dirs list
+setopt localoptions extendedglob
+
+local d s dirs list
 
 if [[ "$SUFFIX" = */* ]]; then
   ISUFFIX="/${SUFFIX#*/}$ISUFFIX"
@@ -17,32 +19,31 @@ else
   s=(-qS/)
 fi
 
-if compset -P +; then
-  dirs="$(dirs -v)"
-  list=("${(f)dirs}")
-  [[ -o pushdminus ]] && dirs="$(awk '{ $1 = '$#list' - $1 - 1;
-  				        printf("%s\t%s\n", $1, $2); }' <<<$dirs)"
-  list=("${(@)list%	*}")
-  c=(-y '$dirs' -k "($list)")
-
-  _description d 'directory stack'
-elif compset -P -; then
-  dirs="$(dirs -v)"
-  list=("${(f)dirs}")
-  [[ ! -o pushdminus ]] && dirs="$(awk '{ $1 = '$#list' - $1 - 1;
-					  printf("%s\t%s\n", $1, $2); }' <<<$dirs)"
-  list=("${(@)list%	*}")
-  c=(-y '$dirs' -k "($list)")
+if [[ -prefix [-+] ]]; then
+  lines=(${(f)"$(dirs -v)"})
+  if [[ ( -prefix - && ! -o pushdminus ) ||
+	( -prefix + && -o pushdminus ) ]]; then
+    integer tot i
+    for (( i = 1, tot = $#lines-1; i <= $#lines; i++, tot-- )); do
+      lines[$i]="$tot -- ${lines[$i]##[0-9]#[	 ]#}"
+    done
+  else
+    for (( i = 1, tot = 0; i <= $#lines; i++, tot++ )); do
+      lines[$i]="$tot -- ${lines[$i]##[0-9]#[	 ]#}"
+    done
+  fi
+  list=(${lines%% *})
 
+  compset -P '[-+]'
   _description d 'directory stack'
+  compadd "$d[@]" -d lines -Q - "$list[@]" 
 else
-  c=(-nu)
-
   if (( $# )); then
     d=( "$@" )
   else
     _description d 'user or named directory'
   fi
+
+  compgen "$d[@]" -nu "$s[@]"
 fi
 
-compgen "$d[@]" "$c[@]" "$s[@]"
diff --git a/Completion/Builtins/_cd b/Completion/Builtins/_cd
index 92a14ec31..e4502459c 100644
--- a/Completion/Builtins/_cd
+++ b/Completion/Builtins/_cd
@@ -37,24 +37,25 @@ elif [[ $PREFIX = [-+]* ]]; then
   local list lines ret=1
 
   # 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*})
+  # 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 = $#list-1; tot >= 0; i++, tot-- )); do
-      list[$i]="$tot${list[$i]##[0-9]#}"
+    for (( i = 1, tot = $#lines-1; i <= $#lines; i++, tot-- )); do
+      lines[$i]="$tot -- ${lines[$i]##[0-9]#[	 ]#}"
+    done
+  else
+    for (( i = 1, tot = 1; i <= $#lines; i++, tot++ )); do
+      lines[$i]="$tot -- ${lines[$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%%[ 	]*})
+  list=(${lines%% *})
   _description expl 'directory stack index'
-  compgen "$expl[@]" -y '$lines' -Q -k list && ret=0
+  compadd "$expl[@]" -d lines -Q - "$list[@]" && ret=0
   [[ -z $compstate[list] ]] && compstate[list]=list && ret=0
   [[ -n $compstate[insert] ]] && compstate[insert]=menu && ret=0