1
0
Fork 0
mirror of https://github.com/jarun/nnn.git synced 2025-02-18 23:34:37 +00:00
nnn/plugins/pskill

36 lines
741 B
Text
Raw Normal View History

2019-11-01 21:54:31 +05:30
#!/usr/bin/env sh
# Description: Fuzzy list and kill a (zombie) process by name
#
2020-05-06 18:41:01 +05:30
# Dependencies: fzf, ps
2019-12-09 18:36:48 +05:30
#
2019-11-01 21:54:31 +05:30
# Note: To kill a zombie process enter "zombie"
#
# Shell: POSIX compliant
# Author: Arun Prakash Jana
2019-11-22 02:14:25 +05:30
printf "Enter process name ['defunct' for zombies]: "
read -r psname
2019-11-01 21:54:31 +05:30
2019-12-09 18:36:48 +05:30
# shellcheck disable=SC2009
2020-11-22 20:09:14 +05:30
if [ -n "$psname" ]; then
if type sudo >/dev/null 2>&1; then
2019-12-09 18:36:48 +05:30
sucmd=sudo
elif type doas >/dev/null 2>&1; then
2019-12-09 18:36:48 +05:30
sucmd=doas
else
sucmd=: # noop
fi
if type fzf >/dev/null 2>&1; then
2019-12-09 18:36:48 +05:30
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 21:54:31 +05:30
fi