dotfiles
Seven years worth of accumulated configuration cruft
dotfiles/scripts/.local/bin/batdaemon
Download raw file: scripts/.local/bin/batdaemon
#!/bin/sh
# Poll my battery and send notifications when it gets low.
# Dependencies: libnotify, dunst
set -eu
while true; do
if [ "$(uname)" = "OpenBSD" ]; then
bat_stat="$(apm | head -1 | cut -d ' ' -f4 | tr -d '%')"
elif [ "$(uname)" = "FreeBSD" ]; then
bat_stat="$(sysctl hw.acpi.battery.life | cut -d' ' -f2)"
elif [ "$(uname)" = "Linux" ]; then
bat_stat="$(cat /sys/class/power_supply/BAT0/capacity)"
fi
[ "$bat_stat" -le 30 ] && {
if [ "$bat_stat" -le 10 ]; then
notify-send -t 2000 -u critical ⚠"BAT: $bat_stat"
else
notify-send -t 2000 -u normal 🔋"BAT: $bat_stat"
fi
}
sleep 300
done