battery_nag, simplify the acceleration and allow it to be turned off.

This commit is contained in:
me
2026-08-19 18:30:45 -07:00
parent f1a7025e07
commit 4d1c461fcf
+27 -16
View File
@@ -41,7 +41,21 @@ if [[ -n "$2" ]]; then
echo "to '$sleep'" echo "to '$sleep'"
fi fi
echo "`date` - Alerting every ${sleep} seconds when under ${alert}%." accelerate="Y"
if [[ -n "$3" ]]; then
echo -n "accelerate changed from '$accelerate' "
accelerate="$3"
echo "to '$accelerate'"
fi
echo "Alerting when under ${alert}%."
echo "Notifying every ${sleep} seconds."
if [[ "$accelerate" == "Y" ]]; then
echo -n "Speeding up notifications as % gets lower."
else
echo -n "Notifcations staying persistent."
fi
echo " (accelerate == $accelerate)"
echo "`date` - Starting Loop" echo "`date` - Starting Loop"
@@ -51,12 +65,13 @@ while true; do
batt=${batt//%/} batt=${batt//%/}
if (( batt <= alert )); then if (( batt <= alert )); then
title="Battery is below ${alert}%!" title="Battery is below ${alert}%"
message="Currently at ${batt}%." message="Currently at ${batt}%"
cmd="`which fyi 2>/dev/null || which notify-send 2>/dev/null`" cmd="`which fyi 2>/dev/null || which notify-send 2>/dev/null`"
if [[ -z "$cmd" ]]; then if [[ -z "$cmd" ]]; then
echo "ERROR: No command found to send notification, exiting." echo "ERROR: No command found to send notification, exiting."
echo "Please install 'fyi' or 'notify-send' to use this script." echo "Please install 'fyi' or 'notify-send' to use this script."
echo "If not using a DE, also ensure 'dunst' or similar is running."
exit 3 exit 3
fi fi
@@ -74,22 +89,18 @@ while true; do
fi fi
time=$sleep time=$sleep
if (( batt <= 2 )); then if [[ "$accelerate" == "Y" ]]; then
echo "Battery under 2, 16x speed." if (( batt > 0 )); then
time=$(( sleep / 16 )) time=$(( time / (alert / batt) ))
elif (( batt <= 5 )); then else
echo "Battery under 5, 8x speed." time=10
time=$(( sleep / 8 ))
elif (( batt <= 8 )); then
echo "Battery under 8, 4x speed."
time=$(( sleep / 4 ))
elif (( batt <= 10 )); then
echo "Battery under 10, 2x speed."
time=$(( sleep / 2 ))
fi fi
fi
# Showing a notification every 10 seconds makes it persistent.
# Any more than that casues multiple to stack which is unnecessary.
if (( time < 10 )); then if (( time < 10 )); then
time=10 time=10
fi fi
echo "`date` - Sleeping for ${time}" echo "`date` - Sleeping for ${time}."
sleep $time sleep $time
done done