1
1
mirror of https://github.com/jarun/nnn.git synced 2024-09-17 15:57:17 +03:00
nnn/plugins/pskill

36 lines
741 B
Plaintext
Raw Normal View History

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