about summary refs log tree commit diff
path: root/Completion/User/_exec_funcs
blob: 2fd64b2309de85792e27566afdaa56af0f300dc2 (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
#autoload

# This should be called from `_arguments' or otherwise the calling
# function has to set up an array named `line' that contains the
# name of the executable as its seconf element or it has to supply
# that name as an argument.
# One option is recognized: `-p' means that we are completing a pair
# of names separated by a slash.

local cmd pair expl

if [[ "$1" = -p ]]; then
  pair=yes
  shift
fi

if (( $# )); then
  cmd="$1"
elif [[ $#line -gt 1 ]]; then
  cmd="$line[2]"
else
  return 1
fi

if [[ -n "$cmd" ]]; then
  if [[ "$cmd" = /* ]]; then
    tmp="$cmd"
  else
    tmp="$PWD/$cmd"
  fi

  if [[ "$tmp" != "$_es_command" ]]; then
    _es_command="$tmp"
    _es_funcs=( "${(@)${(@M)${(@f)$(nm $cmd)}:#[^ ]# [tT] ([^_]|_[^_])*}##* }" )
  fi
  
  if [[ -n "$pair" ]]; then
    if compset -P '*/'; then
      _description expl 'call arc to function'
    else
      _description expl 'call arc from function'
    fi
  else
    _description expl function
  fi
  compadd -M 'r:|_=* r:|=*' - "$_es_funcs[@]"
else
  return 1
fi