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'"
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"
@@ -51,12 +65,13 @@ while true; do
batt=${batt//%/}
if (( batt <= alert )); then
title="Battery is below ${alert}%!"
message="Currently at ${batt}%."
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."
echo "If not using a DE, also ensure 'dunst' or similar is running."
exit 3
fi
@@ -74,22 +89,18 @@ while true; do
fi
time=$sleep
if (( batt <= 2 )); then
echo "Battery under 2, 16x speed."
time=$(( sleep / 16 ))
elif (( batt <= 5 )); then
echo "Battery under 5, 8x speed."
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 ))
if [[ "$accelerate" == "Y" ]]; then
if (( batt > 0 )); then
time=$(( time / (alert / batt) ))
else
time=10
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
time=10
fi
echo "`date` - Sleeping for ${time}"
echo "`date` - Sleeping for ${time}."
sleep $time
done