feat(cron): Add battery charged indicator

This commit is contained in:
Tanguy Herbron 2023-09-14 09:58:29 +02:00
parent 331838de06
commit 5df3a9898c

View File

@ -1,14 +1,23 @@
#!/bin/bash #!/bin/bash
# Crontab entry
# */5 * * * * XDG_RUNTIME_DIR=/run/user/$(id -u) <path to script>
battery_level=$(acpi -b | grep -P -o -m1 "[0-9]+(?=%)") battery_level=$(acpi -b | grep -P -o -m1 "[0-9]+(?=%)")
charging_state=$(acpi -b | grep -P -o -m1 "([A-Z])\w+,") charging_state=$(acpi -b | grep -P -o -m1 "([A-Z])\w+,")
# If laptop is charging, do not make further tests # If laptop is charging, do not make further tests
if [ $charging_state = "Charging," ] if [ $charging_state = "Charging," ] && [ ! -f /tmp/charge_done ]
then then
if [ $battery_level -ge 100 ]
then
/usr/bin/notify-send "Charge completed" "The battery reached 100% charge."
touch /tmp/charge_done
exit exit
fi
fi fi
rm -f /tmp/charge_done
if [ $battery_level -le 5 ] if [ $battery_level -le 5 ]
then then
/usr/bin/notify-send "Battery level critical" "Battery level critically low, plug to avoid shutdown" --urgency=critical /usr/bin/notify-send "Battery level critical" "Battery level critically low, plug to avoid shutdown" --urgency=critical