-
Notifications
You must be signed in to change notification settings - Fork 0
/
dm-kill.sh
executable file
·76 lines (68 loc) · 1.18 KB
/
dm-kill.sh
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
71
72
73
74
75
76
#!/bin/bash
# ____ _
# | _ \ | |
# | |_) | | |
# | __/ |_| |
# |_| \___/
#
set -e
# Variables {{{
dmenu="dmenu \
-i \
-l 25 \
${@} \
"
prompt="$(echo $0 | awk -F '/' '{print $NF;}')"
#prompt="Kill"
# }}}
# sent notification {{{
notify() {
case $2 in
1)
mode=low
;;
2)
mode=normal
;;
3)
mode=critical
;;
*)
mode=normal
;;
esac
notify-send -a ${prompt} -i xfce-mount -u $mode "${1}"
}
# }}}
list=$( \
ps --cols 140 axfo pid,%mem,%cpu,user,cmd k %mem \
| $dmenu -p "${prompt}" \
| awk '{print $1;}'
# | sed 's/ \\_ / ├─ /' \
# | sed 's/| /│ /g' \
# | sed 's/├─ -/├─ /' \
)
if [[ $list -eq 'PID' ]] || [[ -z $list ]]; then
notify 'Canceled' 1
exit 0
else
thesig=$(printf '%s\n' \
"15 SIGTERM Terminate " \
"9 SIGKILL Kill (Not Safe)" \
"2 SIGINT Interrupt " \
"3 SIGQUIT Quit " \
| $dmenu -p 'Send signal:' \
| awk '{print $1;}')
if [ -z "${thesig}" ]; then
notify 'Canceled' 1
exit 0
else
kill="kill -s $thesig"
fi
for i in $list
do
$kill "$i" \
&& notify "Process [${i}] killed (signal ${thesig})" \
|| notify "[${i}] Termination failed" 3
done
fi