about summary refs log tree commit diff
path: root/Completion/Base/_tilde
blob: 2edc2ca24593f4c9e9ce3cdf4fda0a03d0bace75 (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#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
# `compadd -qS/ - "$friends[@]"' or something like that.

local expl suf dirs list lines revlines i ret disp nm="$compstate[nmatches]"

if [[ "$SUFFIX" = */* ]]; then
  ISUFFIX="/${SUFFIX#*/}$ISUFFIX"
  SUFFIX="${SUFFIX%%/*}"
  suf=(-S '')
else
  suf=(-qS/)
fi

_tags users named-directories directory-stack

while _tags; do
  _requested users && _users "$suf[@]" "$@" && ret=0
  _requested named-directories expl 'named directory' \
      compadd "$suf[@]" "$@" - "${(@k)nameddirs}"

  if _requested directory-stack &&
     { ! zstyle -T ":completion:${curcontext}:directory-stack" prefix-needed ||
       [[ "$PREFIX" = [-+]* || nm -eq compstate[nmatches] ]] }; then
    if zstyle -T ":completion:${curcontext}:directory-stack" verbose; then
      integer i

      lines=("${PWD}" "${dirstack[@]}")

      if [[ ( -prefix - && ! -o pushdminus ) ||
	    ( -prefix + && -o pushdminus ) ]]; then
        revlines=( $lines )
        for (( i = 1; i <= $#lines; i++ )); do
          lines[$i]="$((i-1)) -- ${revlines[-$i]}"
        done
      else
        for (( i = 1; i <= $#lines; i++ )); do
          lines[$i]="$((i-1)) -- ${lines[$i]}"
        done
      fi
      list=( ${PREFIX[1]}${^lines%% *} )
      disp=( -ld lines )
    else
      list=( ${PREFIX[1]}{0..${#dirstack}} )
      disp=()
    fi
    _loop -V directory-stack expl 'directory stack' \
        compadd "$suf[@]" "$disp[@]" -Q - "$list[@]" && ret=0
  fi
  (( ret )) || return 0
done