omarchy-dev-link/unlink: strip prior dev-link bin/ from PATH

Sequential 'dev-link A' then 'dev-link B' previously left A/bin in
PATH because the prepend didn't strip the old one. unlink had the
same issue (it was trying to strip $(dirname $0), which only worked
if you invoked unlink via an absolute path that happened to match
the dev-link bin).

Both now read the previous OMARCHY_PATH from /etc/omarchy.conf before
overwriting/deleting it, and strip that path's bin/ from PATH before
prepending the new one (or nothing, for unlink).
This commit is contained in:
Ryan Hughes
2026-06-04 18:34:35 -04:00
parent b887d18b84
commit 6e0079a66d
2 changed files with 17 additions and 3 deletions
+10
View File
@@ -42,10 +42,20 @@ for required in bin default shell; do
fi
done
# Strip any previous dev-link's bin/ from PATH before adding the new one,
# so repeated link calls don't accumulate stale entries.
prior_target=""
if [[ -f /etc/omarchy.conf ]]; then
prior_target=$(sed -n 's/^[[:space:]]*export[[:space:]]\+OMARCHY_PATH="\?\([^"]*\)"\?/\1/p' /etc/omarchy.conf | tail -1)
fi
echo "Pointing Omarchy at $target"
printf 'export OMARCHY_PATH="%s"\n' "$target" | sudo tee /etc/omarchy.conf >/dev/null
export OMARCHY_PATH="$target"
if [[ -n $prior_target && $prior_target != "$target" ]]; then
PATH=$(printf '%s' "$PATH" | tr ':' '\n' | grep -vFx "$prior_target/bin" | paste -sd:)
fi
export PATH="$target/bin:$PATH"
if command -v hyprctl >/dev/null 2>&1 && hyprctl version &>/dev/null; then