From a9baa8f45f5814478915ac36814de942bb76f5f1 Mon Sep 17 00:00:00 2001 From: Lewis Buckley Date: Mon, 20 Apr 2026 12:52:04 +0100 Subject: [PATCH] Migrate existing waybar configs to pin battery to BAT0 (#5369) * Migrate existing waybar configs to pin battery to BAT0 Follow-up to #4918: that PR updated the default template, but existing users keep their copy at ~/.config/waybar/config.jsonc and won't pick up the fix without running omarchy-refresh-waybar (which wipes local customizations). Patch the existing file in place and restart waybar. * Make battery-pin migration tolerant of whitespace variants Per Copilot review: grep/sed patterns now match "battery" : {, "battery":{, and "bat" : "..." variants that hand-edited configs may use. Also only restart waybar when a battery block actually exists to edit. --- migrations/1776674079.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 migrations/1776674079.sh diff --git a/migrations/1776674079.sh b/migrations/1776674079.sh new file mode 100644 index 00000000..6d233599 --- /dev/null +++ b/migrations/1776674079.sh @@ -0,0 +1,10 @@ +echo "Pin waybar battery module to BAT0 to prevent crash on HID battery disconnect" + +CONFIG_FILE=~/.config/waybar/config.jsonc + +if [[ -f "$CONFIG_FILE" ]] \ + && ! grep -Eq '"bat"[[:space:]]*:' "$CONFIG_FILE" \ + && grep -Eq '"battery"[[:space:]]*:[[:space:]]*\{' "$CONFIG_FILE"; then + sed -i -E '/"battery"[[:space:]]*:[[:space:]]*\{/a\ "bat": "BAT0",' "$CONFIG_FILE" + omarchy-restart-waybar +fi