blob: e8163551a32b37d648a4c2fab67cab5f72feca8f (
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# bash completion for ps(1) -*- shell-script -*-
_comp_cmd_ps()
{
local cur prev words cword comp_args
_comp_initialize -- "$@" || return
case $prev in
--help)
_comp_compgen -- -W 'simple list output threads misc all'
return
;;
--info | V | --version)
return
;;
-C)
_comp_compgen_pnames
return
;;
-[Gg] | --[Gg]roup)
_comp_compgen -- -g
return
;;
?(-)p | [^-]*p | --pid)
_comp_compgen_pids
return
;;
--ppid)
_comp_compgen_pids # TODO: Only pids with children?
return
;;
?(-)q | [^-]*q | --quick-pid)
_comp_compgen_pids
return
;;
-s | --sid)
# TODO
return
;;
?(-)t | [^-]*t | --tty)
_comp_expand_glob COMPREPLY '/dev/tty*' &&
_comp_compgen -- -W '"${COMPREPLY[@]}" "${COMPREPLY[@]#/dev/}"'
return
;;
?(-)U | [^-]*U | -u | --[Uu]ser)
_comp_compgen -- -u
return
;;
--format | ?(-)[Oo] | [^-]*[Oo])
# TODO: This doesn't work well when there are multiple options for
# the non-first item (similarly to useradd --groups and others).
local labels=$("$1" L | _comp_awk '{ print $1 }')
_comp_delimited , -W '$labels'
return
;;
esac
if [[ $cur == -* ]]; then
# sed: strip single char dashless ", x," that trip _comp_compgen_help
_comp_compgen_help - <<<"$({
"$1" --help
"$1" --help all
} 2>/dev/null |
command sed -e "s/, [A-Za-z],/,/")" ||
_comp_compgen_usage
fi
} &&
complete -F _comp_cmd_ps ps
# ex: filetype=sh
|