#!/usr/bin/env bash
while sleep 1; do
        ## Battery beep
        if ls /sys/class/power_supply/BAT* &>/dev/null; then
                BAT0=$(</sys/class/power_supply/BAT0/capacity)
                if [[ $BAT0 -le 5 && -z "$BEEPED" && $(</sys/class/power_supply/BAT0/status) == Discharging ]]; then
                        sudo ~/.local/bin/beep 9
                        BEEPED=1
                elif [[ $BAT0 -le 2 && $(</sys/class/power_supply/BAT0/status) == Discharging ]]; then
                        sudo ~/.local/bin/beep 9
                        BEEPED=0
                fi
        fi
done
