From d5ef919e6dec39a186d0febc3d0560e393c9365e Mon Sep 17 00:00:00 2001 From: Hyperling Date: Wed, 19 Aug 2026 16:06:32 -0700 Subject: [PATCH] battery_nag, improve the active process checker and enhance edge case handling. --- files/scripts/battery_nag.sh | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/files/scripts/battery_nag.sh b/files/scripts/battery_nag.sh index 25d198d..05fb541 100755 --- a/files/scripts/battery_nag.sh +++ b/files/scripts/battery_nag.sh @@ -4,16 +4,21 @@ echo "`date` - Checking Active Programs" -ps -ef | grep battery_nag.sh | grep -v grep -active="$?" -if [[ "$active" == 0 ]]; then - echo "Program already running, exiting." +PID="$$" +ps -ef | grep battery_nag.sh | grep -v $$ | grep -v grep + +active=`ps -ef | grep battery_nag.sh | grep -v $$ | grep -vc grep` +if (( "$active" >= 1 )); then + echo "Program already running, exiting. Number of processes: $active" exit 1 fi echo "`date` - Loading Functions" -which battery.function +which battery.function || { + echo "ERROR: Battery function not found, exiting." + exit 2 +} source battery.function echo "`date` - Parsing Parameters" @@ -49,6 +54,11 @@ while true; do title="Battery is below ${alert}%!" message="Currently at ${batt}%." cmd="`which fyi 2>/dev/null || which notify-send 2>/dev/null`" + if [[ -z "$cmd" ]]; then + echo "ERROR: No command found to send notification, exiting." + echo "Please install 'fyi' or 'notify-send' to use this script." + exit 3 + fi $cmd "$title" "$message" status="$?" @@ -77,6 +87,9 @@ while true; do echo "Battery under 10, 2x speed." time=$(( sleep / 2 )) fi + if (( time < 10 )); then + time=10 + fi echo "`date` - Sleeping for ${time}" sleep $time done