]> Sergey Matveev's repositories - nnn.git/commitdiff
plugin pskill
authorArun Prakash Jana <engineerarun@gmail.com>
Fri, 1 Nov 2019 16:24:31 +0000 (21:54 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Fri, 1 Nov 2019 16:24:51 +0000 (21:54 +0530)
plugins/README.md
plugins/pskill [new file with mode: 0755]

index 5163cb2b0e1ecb37e06e679e95dd662395ecb335..e68ce259f6dd1eee42a262465142740b3da15c3f 100644 (file)
@@ -35,6 +35,7 @@ The currently available plugins are listed below.
 | pastebin | sh | - | Paste contents of a text a file ix.io |
 | pdfview | sh | pdftotext/<br>mupdf-tools | View PDF file in `$PAGER` |
 | picker | sh | nnn | Pick files and list one per line (to pipe) |
+| pskill | sh | fzy, sudo/doas | Fuzzy list by name and kill process or zombie |
 | pywal | sh | pywal | Set image as wallpaper, change terminal colorscheme |
 | readit | sh | pdftotext, mpv,<br>pico2wave | Read a PDF or text file aloud |
 | ringtone | sh | date, ffmpeg | Create a variable bitrate mp3 ringtone from file |
diff --git a/plugins/pskill b/plugins/pskill
new file mode 100755 (executable)
index 0000000..dcec180
--- /dev/null
@@ -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