nnn/plugins/pskill

36 lines
741 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
#
2020-05-06 13:11:01 +00:00
# Dependencies: fzf, ps
2019-12-09 13:06:48 +00:00
#
2019-11-01 16:24:31 +00:00
# Note: To kill a zombie process enter "zombie"
#
# Shell: POSIX compliant
# Author: Arun Prakash Jana
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
2019-12-09 13:06:48 +00:00
# shellcheck disable=SC2009
2020-11-22 14:39:14 +00:00
if [ -n "$psname" ]; then
if type sudo >/dev/null 2>&1; then
2019-12-09 13:06:48 +00:00
sucmd=sudo
elif type doas >/dev/null 2>&1; then
2019-12-09 13:06:48 +00:00
sucmd=doas
else
sucmd=: # noop
fi
if type fzf >/dev/null 2>&1; then
2019-12-09 13:06:48 +00:00
fuzzy=fzf
else
exit 1
fi
cmd="$(ps -ax | grep -iw "$psname" | "$fuzzy" | sed -e 's/^[ \t]*//' | cut -d' ' -f1)"
if [ -n "$cmd" ]; then
$sucmd kill -9 "$cmd"
fi
2019-11-01 16:24:31 +00:00
fi