#!/bin/sh
BG=midnightblue # dzen backgrounad
FG=white # dzen foreground
W=72 # width of the dzen bar
SW=100 # width of slave window - not used yet
H=22 # height of the dzen bar
GW=24 # gauge width
GH=8 # gauge height
GBG='#9999dd' # gauge background color
Y=0 # y position
X=1000 # x position
FN="dejaVu sans mono:pixelsize=12"
STAT_CMD='acpiconf -i 0'
TMP_FILE=/tmp/battery.stat
CRT_BAT=15 # critical percentage of battery
LOW_BAT=25 # low percentage of battery
LOW_COL='#ff4747' # color when battery is low
NOR_COL='#22aa22' # normal gauge color
CHG_COL='#007eff' # color when battery is charging
TIME_INT=2 # time intervall in seconds
while true; do
$STAT_CMD > $TMP_FILE
STATE=`sed -n 's/State:[^a-z]*\(.*\)/\1/p' $TMP_FILE `
RCAP=`sed -n 's/Remaining\ capacity:[^0-9]*\([0-9]*\)[^0-9]*/\1/p' $TMP_FILE `
if [ $STATE != "discharging" ] ; then
GFG=$CHG_COL
elif [ $RCAP -le $LOW_BAT ] ; then
GFG=$LOW_COL
# suspend if very low:
if [ $RCAP -le $CRIT_BAT ] ; then
sudo acpiconf -s 3
fi
else
GFG=$NOR_COL
fi
echo -n \ $RCAP\%
eval echo -n $RCAP | gdbar -s o -h $GH -w $GW -fg $GFG -bg $GBG | sed 's/^\ */\ /'
sleep $TIME_INT;
done | dzen2 -x $X -y $Y -tw $W -h $H -fg $FG -bg $BG -fn "$FN" -e ''