-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbattery
40 lines (32 loc) · 1013 Bytes
/
battery
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/sh
# Control variable
# Possible values: NONE, FULL, LOW, CRITICAL
last="NONE"
# Default values for LOW/CRITICAL status
low=25
critical=15
while true; do
# If battery is plugged, do stuff
battery="/sys/class/power_supply/BAT0"
if [ -d $battery ]; then
capacity=$(cat $battery/capacity)
status=$(cat $battery/status)
# If battery full and not already warned about that
if [ "$last" != "FULL" ] && [ "$status" = "Full" ]; then
notify-send " Battery full. Remove the adapter!"
last="FULL"
fi
# If low and discharging
if [ "$last" != "LOW" ] && [ "$status" = "Discharging" ] && \
[ $capacity -le $low ]; then
notify-send " Battery low: $capacity%. Plug in the adapter!"
last=LOW
fi
# If critical and discharging
if [ "$status" = "Discharging" ] && [ $capacity -le $critical ]; then
notify-send -u critical " Battery very low: $capacity%. Plug in the adapter!!!"
last=CRITICAL
fi
fi
sleep 60
done