blob: 600dfb311b34de12e3d925ecdd9c22c73bc6abf7 (
plain) (
blame)
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
|
#!/bin/sh
set -e
readonly TS_FILE="$XDG_DATA_HOME/battery-notification.timestamp"
[ -f "$TS_FILE" ] || touch "$TS_FILE"
cd /sys/class/power_supply/BAT1
read cap <capacity
read status <status
if [ $cap -le 20 -a $status != Charging ]
then
now=`date +%s`
read was <"$TS_FILE"
if (set +e; [ $(($now - ${was:-0} > 60)) -eq 1 ])
then
notify-send -a 'battery' -u critical 'Battery Low' \
'The current battery level is below 20%. Plug the device into a charger ASAP.'
echo $now >"$TS_FILE"
fi
fi
{
printf 'percentage=%s%%\nicon=' $cap
if [ $status = Charging ]; then
echo ""
elif [ $cap -ge 90 ]; then
echo ""
elif [ $cap -ge 80 ]; then
echo ""
elif [ $cap -ge 70 ]; then
echo ""
elif [ $cap -ge 60 ]; then
echo ""
elif [ $cap -ge 50 ]; then
echo ""
elif [ $cap -ge 40 ]; then
echo ""
elif [ $cap -ge 30 ]; then
echo ""
elif [ $cap -ge 20 ]; then
echo ""
elif [ $cap -ge 10 ]; then
echo ""
else
echo ""
fi
} | jo
|