-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskill
executable file
·28 lines (24 loc) · 886 Bytes
/
skill
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
#!/bin/env bash
# Author: sandalbanditten
#mpv License: GPL v3.0
# smart way
selected="$(ps --user "$USER" -F | \
dmenu -l 16 -i -p "Process to kill:" "$@" | \
awk '{print $2" "$11}')";
if [[ -n $selected ]]; then
# Piping No/Yes into dmenu as a safety measure, in case you
answer="$(echo -e "No\nYes" | dmenu -l 16 -i -p "Kill $selected?" "$@")"
if [[ $answer == "Yes" ]]; then
# This echo command prints everything before the first space.
# Luke Smith has a video on why this is most efficient in this case
# An alternative way to do it would be with awk or cut, both are less
# efficient however.
kill -9 "${selected%% *}"
echo "Process $selected has been killed." && exit 0
else
# We want this script to exit with a 1 and not 0 because 1 means
# an error, so this can be handled by other scripts better
echo "Script terminated." && exit 1
fi
fi
exit 0