diff --git a/migrations/1776674079.sh b/migrations/1776674079.sh index 5c95490e..6d233599 100644 --- a/migrations/1776674079.sh +++ b/migrations/1776674079.sh @@ -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