#!/bin/sh

while true; do

    date
    . /sys/class/power_supply/battery/uevent 2>/devnull

    # sourcing /sys/class/power_supply/battery/uevent gives
    # the following values:

    # POWER_SUPPLY_STATUS=Charging  (or: Not Charging)
    #    the blank in 'Not Charging' gives a syntax bug, see the test for
    #    beeing empty POWER_SUPPLY_STATUS below
    # POWER_SUPPLY_VOLTAGE_NOW=4148000
    # POWER_SUPPLY_CURRENT_NOW=-214500
    # POWER_SUPPLY_CHARGE_FULL=925522
    # POWER_SUPPLY_CHARGE_NOW=850731
    # POWER_SUPPLY_TEMP=331
    # POWER_SUPPLY_TIME_TO_EMPTY_NOW=3932100
    # POWER_SUPPLY_TIME_TO_FULL_NOW=1980
    # POWER_SUPPLY_CAPACITY=92

    test -s $POWER_SUPPLY_STATUS && POWER_SUPPLY_STATUS=Notcharging
    printf "%s: %sV %smA, charged %s%%, time to full %ssec\n"     \
        "$POWER_SUPPLY_STATUS"                                    \
        `awk "BEGIN { print $POWER_SUPPLY_VOLTAGE_NOW/1000000 }"` \
        `awk "BEGIN { printf \"%.4s\", $POWER_SUPPLY_CURRENT_NOW/1000 }"`    \
        $POWER_SUPPLY_CAPACITY                                    \
        $POWER_SUPPLY_TIME_TO_FULL_NOW

    sleep 60

done    
