about summary refs log tree commit diff
path: root/Completion/Core/_normal
blob: 1791d247133d17bfb8752332b6b65c8ff2f30559 (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#autoload

local comp command cmd1 cmd2 pat val name i ret=1 _compskip="$_compskip"
local curcontext="$curcontext"

# If we get the option `-s', we don't reset `_compskip'. This ensures
# that a value set in the function for the `-first-' context is kept,
# but that we still use pattern functions when we were called form
# another completion function.

[[ "$1" = -s ]] || _compskip=''

# Completing in command position? If not we set up `cmd1' and `cmd2' as
# two strings we have to search in the completion definition arrays (e.g.
# a path and the last path name component).

command="$words[1]"
if [[ CURRENT -eq 1 ]]; then
  curcontext="${curcontext%:*:*}:-command-:"

  comp="$_comps[-command-]"
  [[ -z "$comp" ]] || "$comp" && ret=0

  return ret
else
  if [[ "$command[1]" == '=' ]]; then
    eval cmd1\=$command
    cmd2="$command[2,-1]"
    curcontext="${curcontext%:*:*}:${cmd2}:"
  elif [[ "$command" == */* ]]; then
    cmd1="$command"
    cmd2="${command:t}"
    curcontext="${curcontext%:*:*}:${cmd2}:"
  else
    cmd1="$command"
    cmd2="$commands[$command]"
    curcontext="${curcontext%:*:*}:${cmd1}:"
  fi
fi

# See if there are any matching pattern completions.

if [[ "$_compskip" != (all|*patterns*) ]]; then
  for i in "${(@)_patcomps[(K)$cmd1]}"; do
    "$i" && ret=0
    if [[ "$_compskip" = *patterns* ]]; then
      break
    elif [[ "$_compskip" = all ]]; then
      _compskip=''
      return ret
    fi
  done
  for i in "${(@)_patcomps[(K)$cmd2]}"; do
    "$i" && ret=0
    if [[ "$_compskip" = *patterns* ]]; then
      break
    elif [[ "$_compskip" = all ]]; then
      _compskip=''
      return ret
    fi
  done
fi

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

name="$cmd1"
comp="$_comps[$cmd1]"

[[ -z "$comp" ]] && name="$cmd2" comp="$_comps[$cmd2]"

# And generate the matches, probably using default completion.

if [[ -n "$comp" ]]; then
  _compskip=patterns
  "$comp" && ret=0
  [[ "$_compskip" = (all|*patterns*) ]] && return ret
elif [[ "$_compskip" != *default* ]]; then
  name=-default-
  comp="$_comps[-default-]"
fi

if [[ "$_compskip" != (all|*patterns*) ]]; then
  for i in "${(@)_postpatcomps[(K)$cmd1]}"; do
    _compskip=default
    "$i" && ret=0
    if [[ "$_compskip" = *patterns* ]]; then
      break
    elif [[ "$_compskip" = all ]]; then
      _compskip=''
      return ret
    fi
  done
  for i in "${(@)_postpatcomps[(K)$cmd2]}"; do
    _compskip=default
    "$i" && ret=0
    if [[ "$_compskip" = *patterns* ]]; then
      break
    elif [[ "$_compskip" = all ]]; then
      _compskip=''
      return ret
    fi
  done
fi

[[ "$name" = -default- && -n "$comp" && "$_compskip" != (all|*default*) ]] &&
  "$comp" && ret=0

_compskip=''

return ret