#!/bin/bash
#########################################################
# 							#
# This is BashStyle-NG  				#
#							#
# Licensed under GNU GENERAL PUBLIC LICENSE v3    	#
#							#
# Copyright 2007 - 2013 Christopher Bratusek		#
#							#
#########################################################

case $1 in
	*acpi )
		check_opt acpi show_battery_load::acpi
		if [[ $? != "1" ]]; then
			load=$(acpi -b | sed -e "s/.* \([1-9][0-9]*\)%.*/\1/")
			out="$(acpi -b)"
			state="$(echo "${out}" | awk '{print $3}')"
			case ${state} in
				charging,)
					statesign="^"
				;;

				discharging,)
					statesign="v"
				;;

				charged,)
					statesign="°"
				;;
			esac
			battery="${statesign}${load}"
			echo $battery
		fi
	;;

	*apm )
		check_opt apm show_battery_load::apm
		if [[ $? != "1" ]]; then
			result="$(apm)"
			case ${result} in
				*'AC on'*)
					state="^"
				;;

				*'AC off'*)
					state="v"
				;;
			esac
			load="${temp##* }"
			battery="${state}${load}"
			echo $battery
		fi
	;;

	* )
		echo -e "\n${ewhite}Usage:\n"
		echo -e "${eorange}show_battery_load${ewhite} |${egreen} --acpi${eiceblue} [show batteryload using acpi]\
		\n${eorange}show_battery_load${ewhite} |${egreen} --apm${eiceblue} [show batteryload using apm]" | column -t
		echo ""
		tput sgr0
	;;
esac
