Cleanup hyprland conf
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user