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.

66 lines
1.6 KiB
Bash
Executable File

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
if [[ "$BATS" == "" ]]; then
echo " no battery "
echo "n/a"
exit 33
fi
cat $BATS | gawk -v LONG="$LONG" -v COLORS="$COLORS" -v BAR="${BAR[*]}" -v COLOR="${COLOR[*]}" -v BW="${BW[*]}" -F "=" '
BEGIN {
split(BAR, bar, / /)
split(COLOR, color, / /)
split(BW, bw, / /)
interval = 100 / length(bar)
efull = 0
enow = 0
status = ""
}
/POWER_SUPPLY_STATUS=/ {
if (status == "") {
if ($2 == "Discharging") {
status = ""
} else if ($2 == "Charging") {
status = "⚡"
}
}
}
/POWER_SUPPLY_ENERGY_FULL=/ { efull += $2 }
/POWER_SUPPLY_ENERGY_NOW=/ { enow += $2 }
END {
load = enow / efull * 100
if (LONG) {
printf("%d%\n%d\n", load, load)
} else {
for (i in bar) {
if (load <= i * interval) {
printf("%s\n%s\n", bar[i], bar[i])
break
}
}
}
for (i in bw) {
if (load <= i * interval) {
if (COLORS) {
printf("%s\n", color[i])
} else {
printf("%s\n", bw[i])
}
break
}
}
}
'