aboutsummaryrefslogtreecommitdiff
path: root/shlowbat
diff options
context:
space:
mode:
authorTimmy Keller <tjk@tjkeller.xyz>2024-08-10 23:22:29 -0500
committerTimmy Keller <tjk@tjkeller.xyz>2024-08-10 23:22:29 -0500
commit8e929bd44420ed9a3bc0b6a030cebbdfcafebf4d (patch)
tree62c41cbd55a958135ede2baebb3fddd7bc5eb6a7 /shlowbat
downloadlowbat-8e929bd44420ed9a3bc0b6a030cebbdfcafebf4d.tar.xz
lowbat-8e929bd44420ed9a3bc0b6a030cebbdfcafebf4d.zip
initial commit
Diffstat (limited to 'shlowbat')
-rwxr-xr-xshlowbat26
1 files changed, 26 insertions, 0 deletions
diff --git a/shlowbat b/shlowbat
new file mode 100755
index 0000000..a02ce56
--- /dev/null
+++ b/shlowbat
@@ -0,0 +1,26 @@
+#!/bin/sh
+psupath=/sys/class/power_supply
+warning_level=0 # 0 = not warned, 1 = warned, 2 = warned critical
+
+sum_props() {
+ for prop in $(cat $psupath/*/$1); do sum=$(( $sum + $prop )); done
+ echo $sum
+}
+is_discharging() { cat $psupath/*/status | grep "Discharging" > /dev/null ; }
+
+while true; do
+ capacity=$(( $(sum_props energy_now) * 100 / $(sum_props energy_full) ))
+
+ if is_discharging; then
+ if [ $capacity -le 5 ] && [ $warning_level -lt 2 ]; then
+ notify_send "Critical Low Battery Warning" "${capacity}% remains"
+ elif [ $capacity -le 20 ] && [ $warning_level -lt 1 ]; then
+ notify_send "Low Battery Warning" "${capacity}% remains"
+ fi
+ else
+ warning_level=0
+ fi
+
+ printf "\r%d%%" $capacity
+ sleep 3
+done