ulthar.xyz > Repos

dotfiles

Seven years worth of accumulated configuration cruft
About Files Commits git clone https://ulthar.xyz/repos/dotfiles/dotfiles.git

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

    
Generated 2025-03-07 15:24:27 -0700 by RepoRat