Skip to content

Instantly share code, notes, and snippets.

@theSage21
Last active October 8, 2015 08:43
Show Gist options
  • Save theSage21/f05ea7ee593e1c6e906d to your computer and use it in GitHub Desktop.
Save theSage21/f05ea7ee593e1c6e906d to your computer and use it in GitHub Desktop.
ratpoison low battery alert
function ratbatalert ()
{
# low battery alert for ratpoison
while true;
do
batt=$(upower -e|grep BAT0)
string_percent=$(upower -i $batt|grep 'percent')
percent=$(sed "s,percentage: ,," <<< $string_percent)
number=${percent::-1}
state=$(upower -i $batt|grep 'state')
sta=$(sed "s,state: ,," <<< $state)
state=`tr '[:lower:]' '[:upper:]' <<< ${sta::3}`
if (($number < $1 )); then
ratpoison -c "echo $state:BatLow:$number ";
fi
sleep 1
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment