From fec52e53d2a10a3d09193c4272535ee02dcb2a91 Mon Sep 17 00:00:00 2001 From: Ryan Hughes Date: Fri, 12 Jun 2026 02:15:51 -0400 Subject: [PATCH] Cleanup hyprland conf --- migrations/user/1781043107.sh | 74 ++++++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 22 deletions(-) diff --git a/migrations/user/1781043107.sh b/migrations/user/1781043107.sh index 77263d31..1237083e 100644 --- a/migrations/user/1781043107.sh +++ b/migrations/user/1781043107.sh @@ -16,34 +16,61 @@ if [[ -e $legacy_current_dir || -L $legacy_current_dir ]]; then fi fi +replace_literal_in_file() { + local file="$1" + local old="$2" + local new="$3" + local tmp + + grep -Fq -- "$old" "$file" || return 0 + + tmp=$(mktemp) + OLD="$old" NEW="$new" awk ' + BEGIN { + old = ENVIRON["OLD"] + new = ENVIRON["NEW"] + } + { + while ((pos = index($0, old)) > 0) { + $0 = substr($0, 1, pos - 1) new substr($0, pos + length(old)) + } + print + } + ' "$file" >"$tmp" + cat "$tmp" >"$file" + rm -f "$tmp" +} + replace_current_path() { local file="$1" [[ -f $file ]] || return 0 - if command -v python3 >/dev/null 2>&1; then - python3 - "$file" "$HOME" <<'PY' -from pathlib import Path -import sys - -path = Path(sys.argv[1]) -home = sys.argv[2] -text = path.read_text() -replacements = { - f"{home}/.config/omarchy/current": f"{home}/.local/state/omarchy/current", - "~/.config/omarchy/current": "~/.local/state/omarchy/current", - "../omarchy/current": "../../.local/state/omarchy/current", + replace_literal_in_file "$file" "$HOME/.config/omarchy/current" "$HOME/.local/state/omarchy/current" + replace_literal_in_file "$file" "~/.config/omarchy/current" "~/.local/state/omarchy/current" + replace_literal_in_file "$file" "../omarchy/current" "../../.local/state/omarchy/current" } -for old, new in replacements.items(): - text = text.replace(old, new) -path.write_text(text) -PY - else - sed -i \ - -e 's|~/.config/omarchy/current|~/.local/state/omarchy/current|g' \ - -e 's|\.\./omarchy/current|../../.local/state/omarchy/current|g' \ - "$file" - fi + +ensure_hyprland_state_path() { + local file="$HOME/.config/hypr/hyprland.lua" + local tmp + + [[ -f $file ]] || return 0 + grep -Fq '/.local/state/?.lua;' "$file" && return 0 + grep -Fq '/default/hypr/bootstrap.lua' "$file" && return 0 + grep -Fq ' .. "/.config/?.lua;"' "$file" || return 0 + + tmp=$(mktemp) + awk ' + !inserted && $0 == " .. \"/.config/?.lua;\"" { + print " .. \"/.local/state/?.lua;\"" + print " .. os.getenv(\"HOME\")" + inserted = 1 + } + { print } + ' "$file" >"$tmp" + cat "$tmp" >"$file" + rm -f "$tmp" } for file in \ @@ -51,11 +78,14 @@ for file in \ "$HOME/.config/foot/foot.ini" \ "$HOME/.config/ghostty/config" \ "$HOME/.config/hypr/hyprland.conf" \ + "$HOME/.config/hypr/hyprland.lua" \ "$HOME/.config/hyprland-preview-share-picker/config.yaml" \ "$HOME/.config/kitty/kitty.conf"; do replace_current_path "$file" done +ensure_hyprland_state_path + relink_current_symlink() { local link="$1" local target suffix