summaryrefslogtreecommitdiff
path: root/etc/completions/_pkill
blob: 8f92fdc55cc4b5b8e2145902cd352d57c88fbd3b (plain)
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
#compdef pkill pgrep
## completion for pkill and pgrep
## Copyright (C) 2008 by Daniel Friesel <derf@derf.homelinux.org>
## License: WTFPL <http://sam.zoy.org/wtfpl>


## Not finished
##  * Some options lack completion / their completion is inspecific

typeset -a arguments
typeset expl

arguments=(
	'-c[count matching processes]'
	'-f[match pattern against full commandline]'
	'-g[match processes in the listed group IDs]:process group ID'
	'-G[match processes with this GID]:group:_groups'
	'-n[select newest matching process]'
	'-o[select oldest matching process]'
	'-P[select processes with this parent PID]:process ID:_pids'
	'-s[select processes with this session ID]:session ID'
	'-t[select processes with this controlling terminal]:terminal:_terminal'
	'-u[select processes owned by effective user]:user:_users'
	'-U[select processes owned by real user]:user:_users'
	'-v[negate the matching]'
	'-x[exact matches]'
	':pattern:_named_process'
)

if [[ ${service} == 'pgrep' ]] {
	arguments+='-d[set output delimiter]:delimiter'
	arguments+='-l[list process name]'
}

function _terminal {
	_path_files -W /dev
}

function _named_process {
	typeset -a pgrep_user
	typeset IFS=$'\n'
	if (( EUID )) {
		pgrep_user=(-u ${EUID})
	}
	_message 'pattern'
	_wanted pattern expl 'process name' \
	compadd ${$(pgrep ${pgrep_user} -l '')#* }
}

_arguments -s ${arguments}
_signals -p