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

names="sbs-20-000b BAT0"
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() {
    file="/sys/class/power_supply/$dir/$1"
    [ -f "$file" ] && cat "$file" || exit 1
}

status=$(fetch status)

if [ "$status" = "Full" ] || [ "$status" = "Unknown" ] ; 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;