commit 03f2153a03a2a2593989300085f136fdfdcbbe0c parent 5300bf8ceecff43628161506d43379e1dc415c19 Author: Claudio Alessi <smoppy@gmail.com> Date: Sun, 24 Dec 2017 20:58:40 +0100 Use uevent to gather informations. Also remove the previous commit check since it should never happen or should be related to an expected battery issue. Diffstat:
M | src/dwmstatus | | | 16 | +++++++--------- |
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/src/dwmstatus b/src/dwmstatus @@ -1,16 +1,14 @@ #!/bin/bash getbattery() { - enow=$(cat /sys/class/power_supply/BAT0/energy_now) - efull=$(cat /sys/class/power_supply/BAT0/energy_full) - vnow=$(cat /sys/class/power_supply/BAT0/voltage_now) + batpath=/sys/class/power_supply/BAT0/ + for kv in $(cat $batpath/uevent); do export $kv ; done + enow=$POWER_SUPPLY_ENERGY_NOW + efull=$POWER_SUPPLY_ENERGY_FULL + vnow=$POWER_SUPPLY_VOLTAGE_NOW + acplugged=$POWER_SUPPLY_PRESENT - if [ $enow -eq 0 -o $vnow -eq 0 ]; then - r=? - else - r=$(echo "($enow * 100 / $vnow) * 100 / ($efull * 100 / $vnow)" |bc) - fi - acplugged="$(cat $(du -a /sys/devices |grep 'AC0/online' |awk '{print $2}'))" + r=$(echo "($enow * 100 / $vnow) * 100 / ($efull * 100 / $vnow)" |bc) r="${r}%" [ $acplugged -eq 1 ] && r="${r}+" || r="${r}-" echo "$r"