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.
This commit is contained in:
Lewis Buckley
2026-04-20 09:45:24 +01:00
parent 1721336745
commit d57e1bb5b4
+4 -2
View File
@@ -2,7 +2,9 @@ echo "Pin waybar battery module to BAT0 to prevent crash on HID battery disconne
CONFIG_FILE=~/.config/waybar/config.jsonc
if [[ -f "$CONFIG_FILE" ]] && ! grep -q '"bat":' "$CONFIG_FILE"; then
sed -i '/"battery": {/a\ "bat": "BAT0",' "$CONFIG_FILE"
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