From 1e43224619b8769d785eba0ba24eb39661cce3b3 Mon Sep 17 00:00:00 2001 From: Aly Raffauf Date: Sat, 3 Aug 2024 17:13:47 -0400 Subject: [PATCH] waybar: nag on battery critical --- homeManagerModules/services/waybar/default.nix | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/homeManagerModules/services/waybar/default.nix b/homeManagerModules/services/waybar/default.nix index eae2e229..5fc6c31a 100644 --- a/homeManagerModules/services/waybar/default.nix +++ b/homeManagerModules/services/waybar/default.nix @@ -83,10 +83,24 @@ "tooltip-format" = "{:%Y-%m-%d | %H:%M}"; }; - "battery" = { + "battery" = let + checkBattery = pkgs.writeShellScript "check-battery" '' + bat=/sys/class/power_supply/BAT0 + CRIT=''${1:-10} + NOTIFY=${lib.getExe' pkgs.libnotify "notify-send"} + + stat=$(cat $bat/status) + perc=$(cat $bat/capacity) + + if [[ $perc -le $CRIT ]] && [[ $stat == "Discharging" ]]; then + $NOTIFY --urgency=critical --icon=dialog-warning "Battery Critical" "Current charge: $perc%". + fi + ''; + in { "format" = "{icon}"; "format-icons" = ["󰁺" "󰁻" "󰁼" "󰁽" "󰁾" "󰁿" "󰂀" "󰂁" "󰂂" "󰁹"]; + "on-update" = "${checkBattery}"; "tooltip-format" = '' {capacity}%: {timeTo}. Draw: {power} watts.'';