1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-10-13 23:31:08 +02:00
zsh/Completion/Base/_tilde
1999-08-23 10:07:17 +00:00

48 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.
local d c s dirs list
if [[ "$SUFFIX" = */* ]]; then
ISUFFIX="/${SUFFIX#*/}$ISUFFIX"
SUFFIX="${SUFFIX%%/*}"
s=(-S '')
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)")
_description d 'directory stack'
else
c=(-nu)
if (( $# )); then
d=( "$@" )
else
_description d 'user or named directory'
fi
fi
compgen "$d[@]" "$c[@]" "$s[@]"