This repository has been archived on 2019-02-28. You can view files and clone it, but cannot push or open issues or pull requests.

23 lines
779 B
Bash

DIR="/sys/class/power_supply"
if [[ "$BLOCK_INSTANCE" == "" ]]; then
for BAT in $DIR/BAT*/; do
[[ -f "${BAT}uevent" ]] && BATS+="${BAT}uevent "
done
else
[[ -f "$DIR/BAT$BLOCK_INSTANCE/uevent" ]] && BATS="$DIR/BAT$BLOCK_INSTANCE/uevent"
fi
[[ "$BATS" == "" ]] && printf "no battery\nn/a\n" && exit 33
ENERGY_FULL=1
ENERGY_NOW=0
STATUS=""
while read -r LINE; do
[[ $LINE =~ POWER_SUPPLY_STATUS=Charging ]] && STATUS="⚡"
[[ $LINE =~ POWER_SUPPLY_ENERGY_FULL=([0-9]+) ]] && ENERGY_FULL=$(($ENERGY_FULL + ${BASH_REMATCH[1]}))
[[ $LINE =~ POWER_SUPPLY_ENERGY_NOW=([0-9]+) ]] && ENERGY_NOW=$(($ENERGY_NOW + ${BASH_REMATCH[1]}))
done <<< $(cat $BATS)
LOAD=$((${ENERGY_NOW} * 100 / ${ENERGY_FULL}))
LONG_TEXT="$STATUS$LOAD%"
SHORT_TEXT="$STATUS$LOAD"