Cleanup hyprland conf
This commit is contained in:
@@ -16,34 +16,61 @@ if [[ -e $legacy_current_dir || -L $legacy_current_dir ]]; then
|
|||||||
fi
|
fi
|
||||||
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() {
|
replace_current_path() {
|
||||||
local file="$1"
|
local file="$1"
|
||||||
|
|
||||||
[[ -f $file ]] || return 0
|
[[ -f $file ]] || return 0
|
||||||
|
|
||||||
if command -v python3 >/dev/null 2>&1; then
|
replace_literal_in_file "$file" "$HOME/.config/omarchy/current" "$HOME/.local/state/omarchy/current"
|
||||||
python3 - "$file" "$HOME" <<'PY'
|
replace_literal_in_file "$file" "~/.config/omarchy/current" "~/.local/state/omarchy/current"
|
||||||
from pathlib import Path
|
replace_literal_in_file "$file" "../omarchy/current" "../../.local/state/omarchy/current"
|
||||||
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",
|
|
||||||
}
|
}
|
||||||
for old, new in replacements.items():
|
|
||||||
text = text.replace(old, new)
|
ensure_hyprland_state_path() {
|
||||||
path.write_text(text)
|
local file="$HOME/.config/hypr/hyprland.lua"
|
||||||
PY
|
local tmp
|
||||||
else
|
|
||||||
sed -i \
|
[[ -f $file ]] || return 0
|
||||||
-e 's|~/.config/omarchy/current|~/.local/state/omarchy/current|g' \
|
grep -Fq '/.local/state/?.lua;' "$file" && return 0
|
||||||
-e 's|\.\./omarchy/current|../../.local/state/omarchy/current|g' \
|
grep -Fq '/default/hypr/bootstrap.lua' "$file" && return 0
|
||||||
"$file"
|
grep -Fq ' .. "/.config/?.lua;"' "$file" || return 0
|
||||||
fi
|
|
||||||
|
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 \
|
for file in \
|
||||||
@@ -51,11 +78,14 @@ for file in \
|
|||||||
"$HOME/.config/foot/foot.ini" \
|
"$HOME/.config/foot/foot.ini" \
|
||||||
"$HOME/.config/ghostty/config" \
|
"$HOME/.config/ghostty/config" \
|
||||||
"$HOME/.config/hypr/hyprland.conf" \
|
"$HOME/.config/hypr/hyprland.conf" \
|
||||||
|
"$HOME/.config/hypr/hyprland.lua" \
|
||||||
"$HOME/.config/hyprland-preview-share-picker/config.yaml" \
|
"$HOME/.config/hyprland-preview-share-picker/config.yaml" \
|
||||||
"$HOME/.config/kitty/kitty.conf"; do
|
"$HOME/.config/kitty/kitty.conf"; do
|
||||||
replace_current_path "$file"
|
replace_current_path "$file"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
ensure_hyprland_state_path
|
||||||
|
|
||||||
relink_current_symlink() {
|
relink_current_symlink() {
|
||||||
local link="$1"
|
local link="$1"
|
||||||
local target suffix
|
local target suffix
|
||||||
|
|||||||
Reference in New Issue
Block a user