From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16446 invoked from network); 8 Oct 1999 17:00:18 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 8 Oct 1999 17:00:18 -0000 Received: (qmail 19231 invoked by alias); 8 Oct 1999 17:00:08 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 8181 Received: (qmail 19205 invoked from network); 8 Oct 1999 17:00:06 -0000 Message-ID: <37FE2305.B07F367F@u.genie.co.uk> Date: Fri, 08 Oct 1999 17:59:49 +0100 From: Oliver Kiddle X-Mailer: Mozilla 4.7 [en] (Win95; I) X-Accept-Language: en MIME-Version: 1.0 To: Zsh workers Subject: PATCH: _cd and _tilde - sorting problem Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit _tilde doesn't work very nicely when there is more than 10 directories in the directory stack and ~[+-] are completed because the list is sorted lexicographically instead of numerically so directories numbered 10-19 appear after 1 but before 2. My fix is to use -V to put the lines in an unsorted group but there may be a better way. I also had to rearrange the code before the compadd so that for ~-, the listing wasn't in reverse order. A very similar change was also necessary for _cd. I have also added -S/ to the compadd because it is a directory that is being completed and I have put local definitions for a few variables which weren't before. Oliver Kiddle *** Completion/Base/_tilde.bak Wed Sep 15 14:20:57 1999 --- Completion/Base/_tilde Fri Oct 8 17:48:51 1999 *************** *** 9,15 **** setopt localoptions extendedglob ! local d s dirs list lines if [[ "$SUFFIX" = */* ]]; then ISUFFIX="/${SUFFIX#*/}$ISUFFIX" --- 9,15 ---- setopt localoptions extendedglob ! local d s dirs list lines revlines i if [[ "$SUFFIX" = */* ]]; then ISUFFIX="/${SUFFIX#*/}$ISUFFIX" *************** *** 21,35 **** 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%% *}) --- 21,36 ---- if [[ -prefix [-+] ]]; then lines=(${(f)"$(dirs -v)"}) + integer i if [[ ( -prefix - && ! -o pushdminus ) || ( -prefix + && -o pushdminus ) ]]; then ! revlines=( $lines ) ! for (( i = 1; i <= $#lines; i++ )); do ! lines[$i]="$((i-1)) -- ${revlines[-$i]##[0-9]#[ ]#}" done else ! for (( i = 1; i <= $#lines; i++ )); do ! lines[$i]="$((i-1)) -- ${lines[$i]##[0-9]#[ ]#}" done fi list=(${lines%% *}) *************** *** 36,42 **** compset -P '[-+]' _description d 'directory stack' ! compadd "$d[@]" -ld lines -Q - "$list[@]" else if (( $# )); then d=( "$@" ) --- 37,43 ---- compset -P '[-+]' _description d 'directory stack' ! compadd "$d[@]" -V dirs -S/ -ld lines -Q - "$list[@]" else if (( $# )); then d=( "$@" ) *** Completion/Builtins/_cd.bak Fri Oct 8 17:17:34 1999 --- Completion/Builtins/_cd Fri Oct 8 17:42:14 1999 *************** *** 34,40 **** # lazy to type pushd. IPREFIX=$PREFIX[1] PREFIX=$PREFIX[2,-1] ! local list lines ret=1 # get the list of directories with their canonical number # and turn the lines into an array, removing the current directory --- 34,40 ---- # lazy to type pushd. IPREFIX=$PREFIX[1] PREFIX=$PREFIX[2,-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 *************** *** 41,61 **** 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]#[ ]#}" done else ! for (( i = 1, tot = 1; i <= $#lines; i++, tot++ )); do ! lines[$i]="$tot -- ${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 [[ -z $compstate[list] ]] && compstate[list]=list && ret=0 [[ -n $compstate[insert] ]] && compstate[insert]=menu && ret=0 --- 41,60 ---- lines=( ${${(f)"$(dirs -v)"}##0*} ) if [[ ( $IPREFIX = - && ! -o pushdminus ) || ( $IPREFIX = + && -o pushdminus ) ]]; then ! integer i ! revlines=( $lines ) ! for (( i = 1; i <= $#lines; i++ )); do ! lines[$i]="$((i-1)) -- ${revlines[-$i]##[0-9]#[ ]#}" done else ! 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 -V dirs -Q - "$list[@]" && ret=0 [[ -z $compstate[list] ]] && compstate[list]=list && ret=0 [[ -n $compstate[insert] ]] && compstate[insert]=menu && ret=0