-
Notifications
You must be signed in to change notification settings - Fork 0
/
dmkill
executable file
·35 lines (29 loc) · 1.09 KB
/
dmkill
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
#!/usr/bin/env bash
#
# Script name: dmkill
# Description: Search for a process to kill.
# Dependencies: dmenu
# GitLab: https://www.gitlab.com/dwt1/dmscripts
# License: https://www.gitlab.com/dwt1/dmscripts/LICENSE
# Contributors: Derek Taylor
# Modifiers: Bharath Saiguhan
# Running ps to get running processes and display in dmenu.
selected="$(ps --user "$(id -u)" -F | \
dmenu -i -l 20 -bw 3 -c -p "Search for process to kill:" | \
awk '{print $2" "$11}')";
# Nested 'if' statements. The outer 'if' statement is what to do
# when we select one of the 'selected' options listed in dmenu.
if [[ -n $selected ]]; then
# Piping No/Yes into dmenu as a safety measure, in case you
# select a process that you don't actually want killed.
answer="$(echo -e "No\nYes" | dmenu -i -c -bw 3 -p "Kill $selected?")"
if [[ $answer == "Yes" ]]; then
selpid="$(awk '{print $1}' <<< "$selected")";
kill -9 "$selpid"
echo "Process $selected has been killed." && exit 0
fi
if [[ $answer == "No" ]]; then
echo "Program terminated." && exit 0
fi
fi
exit 0