#!/bin/bash

# Author: Michael Lustfield
# Desc: Script to execute specified application
#       based on the state of the battery.
# Usage: bateval [l/c] [ac prog] [bat prog

disc=0

if [[ -z $3 ]]; then
	exit
fi

for bat in /proc/acpi/battery/*; do
	if grep discharging "$bat/state"; then
		disc=1
	fi
done

if [[ $disc == 0 ]]; then
	if [[ "$1" == "l" ]]; then
		exec="$(which $2)"
	else
		exec="$2"
	fi
else
	if [[ "$1" == "l" ]]; then
		exec="$(which $3)"
	else
		exec="$3"
	fi
fi

$exec &

exit
