mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-10-13 11:21:13 +02:00
49 lines
1.2 KiB
Text
49 lines
1.2 KiB
Text
#compdef -tilde-
|
|
|
|
# We use all named directories and user names here. If this is too slow
|
|
# for you or if there are too many of them, you may want to use
|
|
# `compgen -k friends -qS/' or something like that. To get all user names
|
|
# if there are no matches in the `friends' array, add
|
|
# `(( compstate[nmatches] )) || compgen -nu -qS/'
|
|
# below that.
|
|
|
|
setopt localoptions extendedglob
|
|
|
|
local d s dirs list lines
|
|
|
|
if [[ "$SUFFIX" = */* ]]; then
|
|
ISUFFIX="/${SUFFIX#*/}$ISUFFIX"
|
|
SUFFIX="${SUFFIX%%/*}"
|
|
s=(-S '')
|
|
else
|
|
s=(-qS/)
|
|
fi
|
|
|
|
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[@]" -ld lines -Q - "$list[@]"
|
|
else
|
|
if (( $# )); then
|
|
d=( "$@" )
|
|
else
|
|
_description d 'user or named directory'
|
|
fi
|
|
|
|
compgen "$d[@]" -nu "$s[@]"
|
|
fi
|
|
|