os/pkgs/check-battery.nix

13 lines
279 B
Nix

self:
with self; ''
status=$(cat /sys/class/power_supply/BAT0/status)
if [ $status != "Discharging" ]; then
exit 0
fi
capacity=$(cat /sys/class/power_supply/BAT0/capacity)
if [ $capacity -lt 20 ]; then
${libnotify}/bin/notify-send -u critical "Battery ''${capacity}%"
fi
''