From: Oliver Kiddle <opk@u.genie.co.uk>
To: Zsh workers <zsh-workers@sunsite.auc.dk>
Subject: PATCH: _cd and _tilde - sorting problem
Date: Fri, 08 Oct 1999 17:59:49 +0100 [thread overview]
Message-ID: <37FE2305.B07F367F@u.genie.co.uk> (raw)
_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
reply other threads:[~1999-10-08 17:00 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=37FE2305.B07F367F@u.genie.co.uk \
--to=opk@u.genie.co.uk \
--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).