nnn/plugins/pskill

31 lines
648 B
Plaintext
Raw Normal View History

2019-11-01 16:24:31 +00:00
#!/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
2019-11-21 20:44:25 +00:00
printf "Enter process name ['defunct' for zombies]: "
read -r psname
2019-11-01 16:24:31 +00:00
if ! [ -z "$psname" ]; then
2019-11-21 20:44:25 +00:00
# shellcheck disable=SC2009
2019-11-01 16:24:31 +00:00
cmd="$(ps -ax | grep -iw "$psname" | fzy | sed -e 's/^[ \t]*//' | cut -d' ' -f1)"
$sucmd kill -9 "$cmd"
fi