diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2012-07-08 04:00:15 +0200 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2012-07-08 04:00:45 +0200 |
commit | 3c6cf7ee3eb1cd768072b21c569a69428bf3ce4c (patch) | |
tree | 44309ce9656e4c8a157c7ce6d4c5af7fd7903ce7 /bin/bat.sh | |
download | dzen2-config-3c6cf7ee3eb1cd768072b21c569a69428bf3ce4c.tar.gz dzen2-config-3c6cf7ee3eb1cd768072b21c569a69428bf3ce4c.tar.xz dzen2-config-3c6cf7ee3eb1cd768072b21c569a69428bf3ce4c.zip |
inital commit
Diffstat (limited to '')
-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 |