diff options
Diffstat (limited to 'bin/bat.sh')
-rw-r--r-- | bin/bat.sh | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/bin/bat.sh b/bin/bat.sh new file mode 100644 index 0000000..e546209 --- /dev/null +++ b/bin/bat.sh @@ -0,0 +1,40 @@ +#!/bin/sh + +STATEFILE='/proc/acpi/battery/BAT0/state' # battery's state file +INFOFILE='/proc/acpi/battery/BAT0/info' # battery's info file + +while true +do + BAT_FULL=`cat $INFOFILE | grep "last full" |cut -d " " -f 9`; + STATUS=`cat $STATEFILE | grep charging |cut -d " " -f 12`; + RCAP=`cat $STATEFILE | grep remaining |cut -d " " -f 8`; + + RPERCT=`expr $RCAP \* 100`; + RPERC=`expr $RPERCT / $BAT_FULL`; + + echo -n '^p(10)' + + if [ $RPERC -ge 100 ] + then + RPERC=100 + fi + + # draw the bar and pipe everything into dzen + COLOR="#999" + IMAGE="power-ac" + + if [ "$STATUS" == "discharging" ] + then + if [ $RPERC -le 20 ] + then + COLOR="#f00" + IMAGE="power-bat-empty" + else + IMAGE="power-bat-full" + fi + fi + + echo $RPERC | gdbar -h 6 -w 50 -fg "${COLOR}" -bg '#444' -l "^i(/home/alex/.dzen2/icons/${IMAGE}.xbm) " -nonl + echo " ${RPERC}%" + sleep 5; +done |