From 5df3a9898cf7fa3c91b6de3dae8b187b38151601 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Thu, 14 Sep 2023 09:58:29 +0200 Subject: [PATCH] feat(cron): Add battery charged indicator --- .config/cron/battery_notifier.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/.config/cron/battery_notifier.sh b/.config/cron/battery_notifier.sh index e8b1ff9..f4028cd 100755 --- a/.config/cron/battery_notifier.sh +++ b/.config/cron/battery_notifier.sh @@ -1,14 +1,23 @@ #!/bin/bash +# Crontab entry +# */5 * * * * XDG_RUNTIME_DIR=/run/user/$(id -u) battery_level=$(acpi -b | grep -P -o -m1 "[0-9]+(?=%)") charging_state=$(acpi -b | grep -P -o -m1 "([A-Z])\w+,") # If laptop is charging, do not make further tests -if [ $charging_state = "Charging," ] +if [ $charging_state = "Charging," ] && [ ! -f /tmp/charge_done ] then - exit + if [ $battery_level -ge 100 ] + then + /usr/bin/notify-send "Charge completed" "The battery reached 100% charge." + touch /tmp/charge_done + exit + fi fi +rm -f /tmp/charge_done + if [ $battery_level -le 5 ] then /usr/bin/notify-send "Battery level critical" "Battery level critically low, plug to avoid shutdown" --urgency=critical