os/pkgs/check-battery.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

14 lines
346 B
Nix
Raw Normal View History

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
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus
${libnotify}/bin/notify-send -u critical "Battery ''${capacity}%"
fi
''