diff options
author | Arun Prakash Jana <engineerarun@gmail.com> | 2019-11-01 21:54:31 +0530 |
---|---|---|
committer | Arun Prakash Jana <engineerarun@gmail.com> | 2019-11-01 21:54:51 +0530 |
commit | 013dad11868df0b389d5ccc87943678abe0bf83e (patch) | |
tree | 58ff5880a0c133596c7378e96b827f207482e654 /plugins/pskill | |
parent | c5c9323d3080854528f7c122a71b1285b2110fc7 (diff) | |
download | nnn-013dad11868df0b389d5ccc87943678abe0bf83e.tar.gz |
plugin pskill
Diffstat (limited to 'plugins/pskill')
-rwxr-xr-x | plugins/pskill | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/plugins/pskill b/plugins/pskill new file mode 100755 index 0000000..dcec180 --- /dev/null +++ b/plugins/pskill @@ -0,0 +1,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 |