From 47c72d59b2fe1234df8fad442f2ad26c2f84fab9 Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Tue, 19 Oct 2021 08:01:55 -0400 Subject: simplify & improve fireslay --- fireslay | 52 ++++++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/fireslay b/fireslay index 1826561..fe5088a 100755 --- a/fireslay +++ b/fireslay @@ -1,8 +1,10 @@ #!/bin/sh -set -e -d=$(mktemp -d) -trap "cd /; rm -r '$d'" EXIT -cd "$d" + +if [ "$1" = -q ] +then + exec 2>/dev/null + shift +fi web_content_pids() { @@ -15,24 +17,26 @@ web_content_pids() } } -lesser_tabs() -{ - web_content_pids > pids - if [ $(wc -l < pids) -gt 1 ] - then - sed 1d < pids | tac - fi -} +web_content_pids >&2 +set -- $(web_content_pids | tac) + +case $# in + 0) + echo "$0: Warning: Not slaying: no Web Content process found." >&2 + exit + ;; + 1) + echo "$0: Warning: Not slaying: only one Web Content process found." >&2 + ps $* >&2 + exit + ;; +esac -FIRST=y -for tab in $(lesser_tabs) -do - if [ "$FIRST" ] - then - FIRST= - ps $tab - (set -x - kill "$tab") - fi - ps $tab -done +( + set -x + ps $1 >&2 + kill $1 +) +r=$? +ps $* >&2 +exit $r -- cgit v1.2.3