commit f5c3c663fd9aeac41f51b4d38b0bf0858f59fc4e parent 9f23b7c2ebda2d13af4bbb137a95ee787d50d969 Author: dwrz <dwrz@dwrz.net> Date: Tue, 31 Oct 2023 19:58:38 +0000 Add check_battery script Diffstat:
A | scripts/check_battery | | | 16 | ++++++++++++++++ |
1 file changed, 16 insertions(+), 0 deletions(-)
diff --git a/scripts/check_battery b/scripts/check_battery @@ -0,0 +1,16 @@ +#!/bin/sh + +readonly CAPACITY="$(cat /sys/class/power_supply/BAT0/capacity)" + +if [ "$(cat /sys/class/power_supply/BAT0/status)" = "Discharging" ]; then + exit 0 +fi + +if [ "${CAPACITY}" -ge 0 ] && [ "${CAPACITY}" -le 3 ]; then + notify-send --urgency critical "CRITICAL BATTERY" \ + "Battery capacity is ${CAPACITY}%, hibernating in 30 seconds." + sleep 30 + systemctl hibernate +elif [ "${CAPACITY}" -ge 5 ] && [ "${CAPACITY}" -le 10 ]; then + notify-send --urgency low "LOW BATTERY" "Battery capacity is ${CAPACITY}%." +fi