Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: _tilde and _cd use compadd -d



I modified _tilde and _cd to use compadd -d.

Index: Completion/Base/_tilde
===================================================================
RCS file: /projects/zsh/zsh/Completion/Base/_tilde,v
retrieving revision 1.1.1.6
diff -u -F^( -r1.1.1.6 _tilde
--- _tilde	1999/08/23 10:07:20	1.1.1.6
+++ _tilde	1999/09/15 12:45:01
@@ -7,8 +7,10 @@
 #   `(( 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"
   SUFFIX="${SUFFIX%%/*}"
@@ -16,33 +18,32 @@
 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[@]"
Index: Completion/Builtins/_cd
===================================================================
RCS file: /projects/zsh/zsh/Completion/Builtins/_cd,v
retrieving revision 1.1.1.9
diff -u -F^( -r1.1.1.9 _cd
--- _cd	1999/08/19 11:18:12	1.1.1.9
+++ _cd	1999/09/15 12:45:01
@@ -37,24 +37,25 @@
   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
 
-- 
Tanaka Akira



Messages sorted by: Reverse Date, Date, Thread, Author