battery warning
This commit is contained in:
parent
0da2b3060f
commit
02d29fb799
|
@ -534,4 +534,51 @@ in rec {
|
||||||
enable = true;
|
enable = true;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
systemd.user= {
|
||||||
|
timers = {
|
||||||
|
battery-check = {
|
||||||
|
Unit.Description = "Warn at low battery levels";
|
||||||
|
Timer = {
|
||||||
|
OnBootSec = "1min";
|
||||||
|
OnUnitActiveSec = "30s";
|
||||||
|
Unit = "battery-check.service";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
services = {
|
||||||
|
battery-check = {
|
||||||
|
Unit.Description = "Warn at low battery levels";
|
||||||
|
Service = let batMon = pkgs.writeShellScript "botMon" ''
|
||||||
|
PATH="$PATH:${pkgs.lib.makeBinPath [
|
||||||
|
pkgs.acpi
|
||||||
|
pkgs.dunst
|
||||||
|
pkgs.gnugrep
|
||||||
|
pkgs.gawk
|
||||||
|
pkgs.systemd
|
||||||
|
]}"
|
||||||
|
acpi -b | grep "Battery 0" | awk -F'[,:%]' '{print $2, $3}' | {
|
||||||
|
read -r status capacity
|
||||||
|
|
||||||
|
if [ "$status" = Discharging -a "$capacity" -lt 2 ]; then
|
||||||
|
dunstify -u critical -a batMon \
|
||||||
|
-h string:x-dunst-stack-tag:batMon \
|
||||||
|
-h int:value:"$capacity" "Battery Critical: ''${capacity}%
|
||||||
|
Hibernating"
|
||||||
|
sleep 5
|
||||||
|
systemctl hibernate
|
||||||
|
elif [ "$status" = Discharging -a "$capacity" -lt 5 ]; then
|
||||||
|
dunstify -u critical -a batMon \
|
||||||
|
-h string:x-dunst-stack-tag:batMon \
|
||||||
|
-h int:value:"$capacity" "Battery Critical: ''${capacity}%"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
in {
|
||||||
|
ExecStart = "${batMon}";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,4 +17,5 @@ systemctl restart --user dunst
|
||||||
systemctl restart --user picom
|
systemctl restart --user picom
|
||||||
systemctl restart --user polybar
|
systemctl restart --user polybar
|
||||||
systemctl restart --user network-manager-applet
|
systemctl restart --user network-manager-applet
|
||||||
|
systemctl restart --user battery-check.timer
|
||||||
exec berry
|
exec berry
|
||||||
|
|
Loading…
Reference in New Issue
Block a user