blob: 378ee3f3832eb3fc6a6b2a5169a1291f4f0992fb (
plain)
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
|
#!/usr/bin/env bash
if [ ! -d /sys/class/power_supply/BAT0 ]; then
echo "<span color='gray'></span> No battery"
exit
fi
current_now=$(cat /sys/class/power_supply/BAT0/current_now)
charge_now=$(cat /sys/class/power_supply/BAT0/charge_now)
charge_full=$(cat /sys/class/power_supply/BAT0/charge_full)
bat_status=$(cat /sys/class/power_supply/BAT0/status)
charge_percent=$(( (100*charge_now) / charge_full ))
if [ "$bat_status" = "Full" ]; then
echo "<span color='gray'></span> Full" && exit
fi
if [ "$bat_status" = "Discharging" ]; then
tot_minutes_remaining=$(( charge_now*60/current_now ))
if [[ $charge_percent -lt 20 ]]; then
icon=""
color="#FF0000"
elif [[ $charge_percent -lt 40 ]]; then
icon=""
color='gray' # ="#FFAE00"
elif [[ $charge_percent -lt 60 ]]; then
icon=""
color='gray' # ="#FFF600"
elif [[ $charge_percent -lt 80 ]]; then
icon=""
color='gray' # ="#A8FF00"
else
icon=""
color='gray' # ="#00FF00"
fi
elif [ "$bat_status" = "Charging" ]; then
tot_minutes_remaining=$(( (charge_full-charge_now)*60/current_now ))
icon=
color="lightblue"
fi
time_remaining=$(printf "%02d:%02d" \
$(( tot_minutes_remaining/60 )) \
$(( tot_minutes_remaining - (tot_minutes_remaining/60)*60 )))
echo "<span color='$color'>$icon</span> $charge_percent% ($time_remaining)"
|