-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbattery_notify.sh
executable file
·64 lines (56 loc) · 1.79 KB
/
battery_notify.sh
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
if [ -s "$XDG_RUNTIME_DIR/battery_script.pid" ]; then
exit
fi
echo $$ >$XDG_RUNTIME_DIR/battery_script.pid
SLEEP_TIME=30
full_flag=0
low_flag=0
crit_flag=0
vcrit_flag=0
while [ true ]; do
capc=$(cat /sys/class/power_supply/BAT*/capacity)
if [[ $(cat /sys/class/power_supply/BAT*/status) != "Discharging" ]]; then # -- charging state
shutdown -c --no-wall # -- cancel pending shutdowns if any
low_flag=0
crit_flag=0
vcrit_flag=0
if (($capc == 100)); then
if ((full_flag != 1)); then
notify-send " energy replenished completely"
full_flag=1
fi
fi
SLEEP_TIME=30
else # -- discharging state
full_flag=0
if (($capc >= 60)); then
SLEEP_TIME=40
else
SLEEP_TIME=30
if (($capc <= 10)); then
SLEEP_TIME=20
if ((low_flag != 1)); then
notify-send " battery low" "\nfind the charger" -u low -t 6000
low_flag=1
fi
fi
if (($capc <= 5)); then
SLEEP_TIME=15
if ((crit_flag != 1)); then
notify-send " critical level" "plug-in charger asap" -u critical -t 6000
crit_flag=1
fi
fi
if (($capc <= 3)); then
SLEEP_TIME=10
if ((vcrit_flag != 1)); then
notify-send " out of juice" "shutdown in 1 minute" -u critical -t 8000
shutdown --no-wall
vcrit_flag=1
fi
fi
fi
fi
#echo "$capc sl_time = $SLEEP_TIME"
sleep $SLEEP_TIME
done