1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-01-17 22:31:12 +01:00
zsh/Completion/Builtins/_popd

44 lines
1.3 KiB
Text
Raw Normal View History

1999-10-21 17:36:39 +02:00
#compdef popd
# This just completes the numbers after +, showing the full directory list
# with numbers. For - we do the same thing, but reverse the numbering (other
# way round if pushdminus is set). Note that this function is also called
1999-10-26 17:36:10 +02:00
# from _cd for cd and pushd.
1999-11-03 10:06:17 +01:00
setopt extendedglob nonomatch
1999-10-26 17:36:10 +02:00
1999-11-15 13:01:46 +01:00
local expl list lines revlines disp
1999-10-26 17:36:10 +02:00
2000-02-15 10:07:09 +01:00
! zstyle -T ":completion:${curcontext}:directory-stack" prefix-needed ||
1999-12-10 15:47:55 +01:00
[[ $PREFIX = [-+]* ]] || return 1
1999-10-26 17:36:10 +02:00
2000-03-23 05:19:26 +01:00
_wanted directory-stack || return 1
2000-02-21 10:53:40 +01:00
2000-02-15 10:07:09 +01:00
if zstyle -T ":completion:${curcontext}:directory-stack" verbose; then
1999-11-12 16:28:24 +01:00
# get the list of directories with their canonical number
# and turn the lines into an array, removing the current directory
2000-01-06 02:13:05 +01:00
lines=("${dirstack[@]}")
1999-11-12 16:28:24 +01:00
if [[ ( $PREFIX[1] = - && ! -o pushdminus ) ||
( $PREFIX[1] = + && -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=( ${PREFIX[1]}${^lines%% *} )
disp=( -ld lines )
1999-10-26 17:36:10 +02:00
else
1999-11-12 16:28:24 +01:00
list=( ${PREFIX[1]}{0..${#dirstack}} )
disp=()
1999-10-26 17:36:10 +02:00
fi
1999-11-12 16:28:24 +01:00
2000-03-23 05:19:26 +01:00
_loop -V directory-stack expl 'directory stack' \
compadd "$@" "$disp[@]" -Q - "$list[@]"