summaryrefslogblamecommitdiffstats
path: root/bin/bat.sh
blob: 49929a134fa32a29c93ae897a301f658159a60af (plain) (tree)



































                                                                      
                                                                                                                  


                         
#!/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}/.dzen2/icons/${IMAGE}.xbm) " -nonl
	echo " ${RPERC}%"
	sleep 5;
done