zsh-workers
 help / color / mirror / code / Atom feed
From: Tanaka Akira <akr@jaist.ac.jp>
To: zsh-workers@sunsite.auc.dk
Subject: PATCH: _tilde and _cd use compadd -d
Date: 15 Sep 1999 21:47:44 +0900	[thread overview]
Message-ID: <rsq3dwgbatr.fsf@crane.jaist.ac.jp> (raw)

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


                 reply	other threads:[~1999-09-15 12:47 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=rsq3dwgbatr.fsf@crane.jaist.ac.jp \
    --to=akr@jaist.ac.jp \
    --cc=zsh-workers@sunsite.auc.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).