diff options
| author | 2019-12-09 18:36:48 +0530 | |
|---|---|---|
| committer | 2019-12-09 18:36:48 +0530 | |
| commit | 885cfd47345017ca8524c259e53949312360fc8f (patch) | |
| tree | 367464beb26ff93da9e5c48c231159122ba88dbb /plugins/pskill | |
| parent | 9614fec13ba9b1363d5845f862384ed4018f2d4b (diff) | |
| download | nnn-885cfd47345017ca8524c259e53949312360fc8f.tar.gz | |
Support both fzf and fzy
Diffstat (limited to 'plugins/pskill')
| -rwxr-xr-x | plugins/pskill | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/plugins/pskill b/plugins/pskill index d02c9fa..fdb5396 100755 --- a/plugins/pskill +++ b/plugins/pskill @@ -2,29 +2,34 @@ # Description: Fuzzy list and kill a (zombie) process by name # +# Requires: fzf or fzy, ps +# # 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 - printf "Enter process name ['defunct' for zombies]: " read -r psname +# shellcheck disable=SC2009 if ! [ -z "$psname" ]; then - # shellcheck disable=SC2009 - cmd="$(ps -ax | grep -iw "$psname" | fzy | sed -e 's/^[ \t]*//' | cut -d' ' -f1)" + if which sudo >/dev/null 2>&1; then + sucmd=sudo + elif which doas >/dev/null 2>&1; then + sucmd=doas + else + sucmd=: # noop + fi + + if which fzf >/dev/null 2>&1; then + fuzzy=fzf + elif which fzy >/dev/null 2>&1; then + fuzzy=fzy + else + exit 1 + fi + + cmd="$(ps -ax | grep -iw "$psname" | "$fuzzy" | sed -e 's/^[ \t]*//' | cut -d' ' -f1)" $sucmd kill -9 "$cmd" fi |