about summary refs log tree commit diff
path: root/Completion/Base/_tilde
blob: d03030821242a7cf3339460e6a69f3666b7b111d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#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 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)")
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)")
else
  c=(-nu)
fi

compgen "$c[@]" "$s[@]"