waybar: nag on battery critical

This commit is contained in:
Aly Raffauf 2024-08-03 17:13:47 -04:00
parent f0b064c19b
commit 1e43224619

View file

@ -83,10 +83,24 @@
"tooltip-format" = "{:%Y-%m-%d | %H:%M}"; "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" = "{icon}";
"format-icons" = ["󰁺" "󰁻" "󰁼" "󰁽" "󰁾" "󰁿" "󰂀" "󰂁" "󰂂" "󰁹"]; "format-icons" = ["󰁺" "󰁻" "󰁼" "󰁽" "󰁾" "󰁿" "󰂀" "󰂁" "󰂂" "󰁹"];
"on-update" = "${checkBattery}";
"tooltip-format" = '' "tooltip-format" = ''
{capacity}%: {timeTo}. {capacity}%: {timeTo}.
Draw: {power} watts.''; Draw: {power} watts.'';