nixcfg/homeManagerModules/services/waybar/scripts/check-battery.sh
Aly Raffauf 069576df3d
home/services: set PATH env vars (#103)
* mako: setup binPath

* swayidle: setup binPath

* randomWallpaper: make bin PATH and move script to separate file

* waybar: setup binPath

* hyprland,sway: don't import all vars for systemd services
2024-08-29 21:04:57 -04:00

19 lines
469 B
Bash
Executable file

#!/usr/bin/env bash
if [ -d /sys/class/power_supply/BAT0 ]; then
BAT=/sys/class/power_supply/BAT0
elif [ -d /sys/class/power_supply/BAT1 ]; then
BAT=/sys/class/power_supply/BAT1
else
echo "No battery found."
exit 1
fi
CRIT=''${1:-10}
STAT=$(cat $BAT/status)
PERC=$(cat $BAT/capacity)
if [[ $PERC -le $CRIT ]] && [[ $STAT == "Discharging" ]]; then
notify-send --urgency=critical --icon=dialog-error "Battery Critical" "Current charge: $PERC%".
fi