Files
env-ansible/files/scripts/battery_nag.sh
T
2026-08-19 14:14:13 -07:00

48 lines
881 B
Bash
Executable File

#!/usr/bin/env bash
# 20260819 Hyperling
# Call notify-send to alert the user every 5 minutes once the battery is low
echo "`date` - Loading Functions"
#which battery.function
source battery.function
echo "`date` - Parsing Parameters"
# Default to 20%.
alert=20
if [[ -n "$1" ]]; then
alert="$1"
fi
# Default to 5 minutes.
sleep=300
if [[ -n "$2" ]]; then
sleep="$2"
fi
echo "`date` - Alerting every ${sleep} seconds when under ${alert}%."
echo "`date` - Starting Loop"
while true; do
batt=`battery-display`
batt=${batt//%/}
if (( batt <= alert )); then
title="Battery is below ${alert}%!"
message="Currently at ${batt}%."
cmd="`which fyi 2>/dev/null || which notify-send 2>/dev/null`"
$cmd "$title" "$message"
status="$?"
echo "`date` - Nag returned status ${status}."
else
echo "`date` - Battery at ${batt}%, did not nag."
fi
sleep $sleep
done