aboutsummaryrefslogtreecommitdiff
path: root/Completion/Core/_normal
blob: ba7f2123f2ce6a8e30b523ca29f34df588915b97 (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
#autoload

local comp command cmd1 cmd2 pat val name i ret=1

# 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
  comp="$_comps[-command-]"
  [[ -z "$comp" ]] || "$comp" && ret=0

  return ret
elif [[ "$command[1]" == '=' ]]; then
  eval cmd1\=$command
  cmd2="$command[2,-1]"
elif [[ "$command" == */* ]]; then
  cmd1="$command"
  cmd2="${command:t}"
else
  cmd1="$command"
  cmd2=$(whence -p $command)
fi

# See if there are any matching pattern completions.

for i in "$_patcomps[@]"; do
  pat="${i% *}"
  val="${i#* }"
  if [[ "$cmd1" == $~pat || "$cmd2" == $~pat ]]; then
    "$val" && ret=0
    if (( $+_compskip )); then
      unset _compskip
      return ret
    fi
  fi
done

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

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

if [[ -z "$comp" ]]; then
  name="$cmd2"
  comp="$_comps[$cmd2]"
fi

# And generate the matches, probably using default completion.

if [[ -z "$comp" ]]; then
  name=-default-
  comp="$_comps[-default-]"
fi
[[ -z "$comp" ]] || "$comp" && ret=0

return ret