1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-02 10:01:11 +02:00

zsh-workers/7840

This commit is contained in:
Tanaka Akira 1999-09-15 12:48:58 +00:00
parent 2b5c62436c
commit defa4a7fa0
2 changed files with 31 additions and 29 deletions

View file

@ -7,7 +7,9 @@
# `(( 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"
@ -17,32 +19,31 @@ 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[@]"

View file

@ -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