From 83f4374903771fa2dbc28025e9d00da55cb85f2f Mon Sep 17 00:00:00 2001 From: "Kirill A. Korinsky" Date: Fri, 29 Nov 2024 22:30:03 +0100 Subject: [PATCH] Simplify `stumpwm_pid` by using only `pgrep` Seems that `pgrep` exists everywhere, for example in Debian it is installed from the same package which installs `ps` and `kill`. --- util/stumpish/stumpish | 41 +++++++++-------------------------------- 1 file changed, 9 insertions(+), 32 deletions(-) diff --git a/util/stumpish/stumpish b/util/stumpish/stumpish index a05bc0b..964df42 100755 --- a/util/stumpish/stumpish +++ b/util/stumpish/stumpish @@ -40,38 +40,15 @@ fi stumpwm_pid () { - local pid=$$ - - while : - do - if [ $pid -eq 1 ] - then - echo "StumpWM not found in the process tree, are you sure a graphical " 1>&2 - echo "session is running and StumpWM is your WM? If you think this is " 1>&2 - echo "a bug in stumpish, please report it." 1>&2 - echo 1>&2 - exit 1 - elif [ -e "/proc/${pid}/comm" -a "$(cat /proc/${pid}/comm 2>/dev/null)" = "stumpwm" ] - then - STUMPWM_PID=$pid - break - elif [ -n "$(which pgrep 2>/dev/null)" ] - then - pid=$(pgrep stumpwm) - if [ -n $pid ] - then - STUMPWM_PID=$pid - break - else - pid=1 - fi - elif [ -e /proc/$pid/stat ] - then - pid=$(cut -f 4 -d " " < /proc/$pid/stat) - else - pid=1 - fi - done + STUMPWM_PID=$(pgrep stumpwm) + + if [ -z "$STUMPWM_PID" ]; then + echo "StumpWM not found in the process tree, are you sure a graphical " 1>&2 + echo "session is running and StumpWM is your WM? If you think this is " 1>&2 + echo "a bug in stumpish, please report it." 1>&2 + echo 1>&2 + exit 1 + fi } wait_result ()