2021-02-12 23:20:57 +01:00
|
|
|
#!/usr/bin/env sh
|
2020-05-20 18:34:34 +02:00
|
|
|
|
|
|
|
######################################################################
|
2020-05-23 15:47:21 +02:00
|
|
|
# @author : swytch
|
|
|
|
# @file : bat_notify
|
2020-06-25 18:19:40 +02:00
|
|
|
# @license : MIT
|
2020-05-23 15:47:21 +02:00
|
|
|
# @created : Wednesday May 20, 2020 17:54:08 CEST
|
2020-05-20 18:34:34 +02:00
|
|
|
#
|
2020-05-23 15:47:21 +02:00
|
|
|
# @description : send a notification with charge level
|
2020-05-20 18:34:34 +02:00
|
|
|
######################################################################
|
|
|
|
|
2020-05-06 03:20:19 +02:00
|
|
|
|
|
|
|
notify() { \
|
|
|
|
for x in /sys/class/power_supply/BAT?/capacity;
|
|
|
|
do
|
|
|
|
case "$(cat "$x")" in
|
|
|
|
1[0-9]) notify-send -u "normal" "Battery is running low ($(cat "$x")%)" "Please plug your computer to a power source" ;;
|
|
|
|
[0-9]) notify-send -u "critical" "Battery is dangerously low ($(cat "$x")%)" "Please plug your computer to a power source - <b>NOW!</b>" ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
update() { \
|
2020-08-26 13:09:35 +02:00
|
|
|
# We want the notification to be sent every 5 mins
|
2020-05-06 03:20:19 +02:00
|
|
|
# But only if the computer is unplugged
|
|
|
|
if [ "$(cat /sys/class/power_supply/AC/online)" = 0 ]; then
|
2021-02-13 20:17:30 +01:00
|
|
|
notify && kill -36 $(pidof dwmblocks)
|
2020-05-06 03:20:19 +02:00
|
|
|
fi
|
|
|
|
wait
|
|
|
|
}
|
|
|
|
|
2021-02-13 20:17:30 +01:00
|
|
|
update
|