From defa4a7fa08ba3b9020a971d189c5ded4e151d5f Mon Sep 17 00:00:00 2001 From: Tanaka Akira Date: Wed, 15 Sep 1999 12:48:58 +0000 Subject: zsh-workers/7840 --- Completion/Builtins/_cd | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'Completion/Builtins') 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 -- cgit 1.4.1