Skip to content

Instantly share code, notes, and snippets.

@fritz0705
Created December 25, 2011 18:27
Show Gist options
  • Select an option

  • Save fritz0705/1519577 to your computer and use it in GitHub Desktop.

Select an option

Save fritz0705/1519577 to your computer and use it in GitHub Desktop.
#!/bin/sh
write() {
echo $*
if [ "$DISPLAY" != "" ]
then
echo $* | dzen2 -tw 256 -p 2 -bg red -fg white -ta l
fi
}
energy_now=0
energy_total=0
for i in /sys/class/power_supply/BAT*
do
if [ -f $i/energy_now ]
then
bat_enow=`cat $i/energy_now`
bat_etot=`cat $i/energy_full`
else
bat_enow=`cat $i/charge_now`
bat_etot=`cat $i/charge_full`
fi
energy_now=`expr $energy_now + $bat_enow`
energy_total=`expr $energy_total + $bat_etot`
done
perc=`expr $energy_now '*' 100 / $energy_total`
write "$energy_now / $energy_total ($perc %)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment