#!/bin/bash

# a horribly written script to find the battery percentage
# It works, though and NO BODY ELSE HAS WRITTEN ONE!
# for OS X Tiger


CAPA_CITY=`/usr/sbin/ioreg -w0 -l |	    
grep LegacyBatteryInfo | 
cut -d\" -f5 - |
sed 's/=//g;s/,//g'`		    

CURRENTLY=`/usr/sbin/ioreg -w0 -l |	    
grep LegacyBatteryInfo | 
cut -d\" -f11 - |
sed 's/=//g;s/,//g'`		    

AMOUNT=$(( ($CURRENTLY * 100) / $CAPA_CITY))

#echo "capacity is : $CAPA_CITY"   
#echo "current is : $CURRENTLY"

if [ "$1" = "-s" ] ; then	    # a short version for geek tool
	echo "$AMOUNT%"
else
	echo "battery is $AMOUNT% charged"
fi


