Tako rzecze Tube (w e-mailu datowanym 2007-03-17, 10:28):
> for anyone who might be interested - here is some code for displaying
> the remaining capacity for notebook users in the statusbar:
>
> export CAPACITY=`awk '/last/ { sum += $4 } END { print sum }' /proc/acpi/battery/BAT*/info`
> while true
> do
> echo `awk '/remaining/ { sum += $3 } END { print int (sum * 100 / ENVIRON["CAPACITY"] + .5) "%" }' /proc/acpi/battery/BAT*/state` `/bin/date '+%x %H:%M:%S'` `uptime | sed 's/.*://; s/,//g'`
> sleep 1
> done | dwm
>
> that considers even serveral rechargeable batteries. so, my question is:
> has anybody maybe a more efficient or more elegant way of displaying
> that?
I do it this way (however it only takes into account a single chosen battery):
BATTERY=C1C5 ### <- Battery ID
cat /proc/acpi/battery/${BATTERY}/state | grep ' charged' 2>&1 >/dev/null && TIME_LEFT="" || DO_BATTERY=1
if [[ -n ${DO_BATTERY} ]]; then
TIME_LEFT=`acpi -t | head -n1 | sed -r \
's/^.*Battery....//; s/discharging, /-/; s/charging, /+/; s/,//g; s/ ([0-9][0-9]:[0-9][0-9]):[0-9][0-9] .*$/ \1 /'`
fi
###
Then you can do whatever you want with ${TIME_LEFT}. This is probably not very elegant, but works fine for me.
[a]
-- . Antoni Grzymala - antoni (at) chopin.edu.pl -------------------. | OpenPGP KeyID EB315583 available now from a keyserver near you | | Fingerprint A819 6D2E D5EB D9E0 D2D9 7AF6 2FAF 4A11 EB31 5583 | `----------------------------------------------------------------'
This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 14:39:25 UTC