about summary refs log tree commit diff
path: root/Completion/Base/Core/_dispatch
blob: 3f6fe5b97c484bd1e00328e750882a569a8f1cea (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#autoload

local comp pat val name i ret=1 _compskip="$_compskip"
local curcontext="$curcontext" service str noskip
local -a match mbegin mend

# If we get the option `-s', we don't reset `_compskip'.

if [[ "$1" = -s ]]; then
  noskip=yes
  shift
fi

[[ -z "$noskip" ]] && _compskip=

curcontext="${curcontext%:*:*}:${1}:"

shift

# See if there are any matching pattern completions.

if [[ "$_compskip" != (all|*patterns*) ]]; then

  for str in "$@"; do
    [[ -n "$str" ]] || continue
    service="${_services[$str]:-$str}"
    for i in "${(@)_patcomps[(K)$str]}"; do
      if [[ $i = (#b)"="([^=]#)"="(*) ]]; then
	service=$match[1]
	i=$match[2]
      fi
      eval "$i" && ret=0
      if [[ "$_compskip" = *patterns* ]]; then
        break
      elif [[ "$_compskip" = all ]]; then
        _compskip=''
        return ret
      fi
    done
  done
fi

# Now look up the names in the normal completion array.

ret=1
for str in "$@"; do
  [[ -n "$str" ]] || continue
  # The following means we look up the names of commands
  # after stripping quotes.  This is presumably correct,
  # but do we need to do the same elsewhere?
  str=${(Q)str}
  name="$str"
  comp="${_comps[$str]}"
  service="${_services[$str]:-$str}"

  [[ -z "$comp" ]] || break
done

# And generate the matches, probably using default completion.

if [[ -n "$comp" && "$name" != "${argv[-1]}" ]]; then
  _compskip=patterns
  eval "$comp" && ret=0
  [[ "$_compskip" = (all|*patterns*) ]] && return ret
fi

if [[ "$_compskip" != (all|*patterns*) ]]; then
  for str; do
    [[ -n "$str" ]] || continue
    service="${_services[$str]:-$str}"
    for i in "${(@)_postpatcomps[(K)$str]}"; do
      _compskip=default
      eval "$i" && ret=0
      if [[ "$_compskip" = *patterns* ]]; then
        break
      elif [[ "$_compskip" = all ]]; then
        _compskip=''
        return ret
      fi
    done
  done
fi

[[ "$name" = "${argv[-1]}" && -n "$comp" &&
   "$_compskip" != (all|*default*) ]] &&
  service="${_services[$name]:-$name}" &&
   eval "$comp" && ret=0

_compskip=''

return ret