summaryrefslogtreecommitdiff
path: root/.local/bin/statusbar/battery
blob: a70e49af3223659a3a47acd6c6748a0d45dc0e4d (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
#!/bin/sh
for battery in /sys/class/power_supply/BAT?
do
	# Get its remaining capacity and charge status.
	capacity=$(cat "$battery"/capacity) || break
	status=$(sed "s/[Dd]ischarging/discharging/;s/[Nn]ot charging/not_charging/;s/[Cc]harging/charging/;s/[Uu]nknown/unknown/;s/[Ff]ull/full/" "$battery"/status)

    if [ "$status" = "charging"]; then
        if [ "$capacity" -le 20 ]; then
            icon=""
        elif [ "$capacity" -le 40 ]; then
            icon=""
        elif [ "$capacity" -le 60 ]; then
            icon=""
        elif [ "$capacity" -le 80 ]; then
            icon=""
        elif [ "$capacity" -lt 95 ]; then
            icon=""
        elif [ "$capacity" -le 100 ]; then
            icon=""
        fi
    elif [ "$status" = "discharging" ]; then
        if [ "$capacity" -le 20 ]; then
            icon=""
        elif [ "$capacity" -le 40 ]; then
            icon=""
        elif [ "$capacity" -le 60 ]; then
            icon=""
        elif [ "$capacity" -le 80 ]; then
            icon=""
        elif [ "$capacity" -lt 95 ]; then
            icon=""
        elif [ "$capacity" -le 100 ]; then
            icon=""
        fi
    elif [ "$status" = "full" ]; then
        icon=""
    fi

	printf "%s %s%% " "$icon" "$capacity"
done | sed 's/ *$//'