aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/pskill
blob: dcec180cd368045bf7312c7ad2e8b1a812922d9f (plain) (blame)
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
#!/usr/bin/env sh

# Description: Fuzzy list and kill a (zombie) process by name
#
# Note: To kill a zombie process enter "zombie"
#
# Shell: POSIX compliant
# Author: Arun Prakash Jana

is_cmd_exists () {
    which "$1" > /dev/null 2>&1
    echo $?
}

if [ "$(is_cmd_exists sudo)" -eq "0" ]; then
    sucmd=sudo
elif [ "$(is_cmd_exists doas)" -eq "0" ]; then
    sucmd=doas
else
    sucmd=: # noop
fi

echo -n "Enter process name ['defunct' for zombies]: "
read psname

if ! [ -z "$psname" ]; then
    cmd="$(ps -ax | grep -iw "$psname" | fzy | sed -e 's/^[ \t]*//' | cut -d' ' -f1)"
    $sucmd kill -9 "$cmd"
fi