summaryrefslogtreecommitdiff
path: root/battery
blob: dc3724ecf3a038648aed64c57d45976757c8813e (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
#!/bin/sh

names="sbs-20-000b BAT1"
dir=""

for n in $names; do
    if [ -d "/sys/class/power_supply/$n" ] ; then
        dir=$n
        break
    fi;
done

if [ -z "$dir" ]; then
    echo \?
    exit 0
fi

fetch() {
    cat /sys/class/power_supply/$dir/$1
}

status=$(fetch status)

if [ "$status" = "Full" ] ; then
    echo $status
else

    if [ "$status" = "Discharging" ]; then
  time=$(fetch time_to_empty_avg)
    else
  time=$(fetch time_to_full_avg)
    fi;

    hours=$(($time/3600))
    minutes=$(($time/60-$hours*60))

    echo $status $(fetch capacity)%, "$hours"h "$minutes"m
fi;