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

PATCH: _cd and _tilde - sorting problem



_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



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