about summary refs log tree commit diff
path: root/Completion/User/_gdb
blob: fc882ff90aa9910b0aed62732c610620fb1f7e36 (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
#compdef gdb

# This uses the configuration keys `ps_args' and `ps_listargs'
# described in the `_wait' function.

local cur="$words[CURRENT]" prev w list ret=1 expl

[[ "$PREFIX" = --* ]] &&
    _arguments -- '*=(CORE|SYM)FILE:core file:_files' \
		  '*=EXECFILE:executable:_files \*\(\*\)' \
		  '*=TTY:terminal device:compadd /dev/tty\*' && return 0

if compset -P '-(cd|directory)='; then
  _files -/
elif compset -P '-tty='; then
  _description expl 'terminal device'
  compadd "$expl[@]" - /dev/tty*
elif compset -P '-(exec|se)='; then
  _description expl executable
  _files "$expl[@]" -/g '*(*)'
elif compset -P '-(symbols|core|command)='; then
  _files
elif [[ "$PREFIX" = -* ]]; then
  _description expl option
  compadd "$expl[@]" -QS '' - -symbols\= -exec\= -se\= -core\= -command\= \
                              -directory\= -cd\= -tty\=
  compadd "$expl[@]" - -help -h -s -e -c -x -d -nx -n -quiet -q -batch \
                       -fullname -f -b
else
  prev="$words[CURRENT-1]"

  case "$prev" in
  (-d) _files -/ && return 0 ;;
  (-[csx]) _files && return 0 ;;
  (-e) _description expl executable
       _files "$expl[@]" -/g '*(*)' && return 0 ;;
  (-b) _description -V expl 'baud rate'
       compadd "$expl[@]" 0 50 75 110 134 150 200 300 600 1200 1800 2400 4800 \
                          9600 19200 38400 57600 115200 230400 && return 0 ;;
  esac
  w=( "${(@)words[2,-1]}" )
  while [[ "$w[1]" = -* ]]; do
    [[ "$w[1]" = -[decsxb] ]] && shift 1 w
    shift 1 w
  done

  if [[ $#w -gt 1 ]]; then
    _files && ret=0
    _description expl 'process ID'
    list=("${(@M)${(f)$(ps ${=compconfig[ps_listargs]:-$=compconfig[ps_args]} 2>/dev/null)}[2,-1]:#[ 	]#${PREFIX}[0-9]#${SUFFIX}[ 	]*${w[1]:t}*}")
    compadd "$expl[@]" -ld list - ${${${(M)${(f)"$(ps $=compconfig[ps_args] 2>/dev/null)"}:#*${w[1]:t}*}## #}%% *} && ret=0

    return ret
  else
    _description expl executable
    _files "$expl[@]" -/g '*(*)'
  fi
fi