Make dev unlink reset Omarchy path defensively

This commit is contained in:
Ryan Hughes
2026-06-07 16:35:54 -04:00
parent 5178405d19
commit 17f024d481
5 changed files with 70 additions and 27 deletions
+20 -2
View File
@@ -3,26 +3,44 @@
# omarchy:summary=Show the current Omarchy dev-link state # omarchy:summary=Show the current Omarchy dev-link state
# omarchy:group=dev # omarchy:group=dev
default_target="/usr/share/omarchy"
configured="$default_target"
conf_present=0
linked=0
if [[ -f /etc/omarchy.conf ]]; then if [[ -f /etc/omarchy.conf ]]; then
conf_present=1
configured=$( configured=$(
OMARCHY_PATH= OMARCHY_PATH=
# shellcheck disable=SC1091 # shellcheck disable=SC1091
. /etc/omarchy.conf . /etc/omarchy.conf
printf '%s' "${OMARCHY_PATH:-<empty>}" printf '%s' "${OMARCHY_PATH:-<empty>}"
) )
if [[ $configured != "$default_target" ]]; then
linked=1
fi
fi
if (( linked )); then
echo "dev-link: ACTIVE" echo "dev-link: ACTIVE"
echo " /etc/omarchy.conf -> OMARCHY_PATH=$configured" echo " /etc/omarchy.conf -> OMARCHY_PATH=$configured"
else else
configured="/usr/share/omarchy (default)"
echo "dev-link: inactive" echo "dev-link: inactive"
if (( conf_present )); then
echo " /etc/omarchy.conf -> OMARCHY_PATH=$configured (default guard)"
fi
fi fi
echo " current shell: OMARCHY_PATH=${OMARCHY_PATH:-<unset>}" echo " current shell: OMARCHY_PATH=${OMARCHY_PATH:-<unset>}"
if [[ -f /etc/omarchy.conf && "${OMARCHY_PATH:-}" != "$configured" ]]; then if (( linked )) && [[ ${OMARCHY_PATH:-} != "$configured" ]]; then
echo echo
echo "Note: this shell predates dev-link. Open a new shell to pick up the change," echo "Note: this shell predates dev-link. Open a new shell to pick up the change,"
echo "or 'export OMARCHY_PATH=$configured' to update just this shell." echo "or 'export OMARCHY_PATH=$configured' to update just this shell."
elif (( ! linked )) && [[ ${OMARCHY_PATH:-$default_target} != "$default_target" ]]; then
echo
echo "Note: no dev-link is configured, but this shell still has a stale OMARCHY_PATH."
echo "Open a new shell or run 'export OMARCHY_PATH=$default_target'."
fi fi
if command -v hyprctl >/dev/null 2>&1 && hyprctl version &>/dev/null; then if command -v hyprctl >/dev/null 2>&1 && hyprctl version &>/dev/null; then
+42 -19
View File
@@ -14,38 +14,56 @@ if [[ ${1:-} == "-h" || ${1:-} == "--help" ]]; then
cat <<USAGE cat <<USAGE
Usage: omarchy dev unlink Usage: omarchy dev unlink
Removes /etc/omarchy.conf so OMARCHY_PATH falls back to /usr/share/omarchy Writes /etc/omarchy.conf defensively so OMARCHY_PATH resolves to
(the package install). Updates Hyprland/systemd session env and restarts /usr/share/omarchy (the package install), even from stale session env.
omarchy-shell so live state matches. Updates Hyprland/systemd session env and restarts omarchy-shell so live
state matches.
USAGE USAGE
exit 0 exit 0
fi fi
if [[ ! -f /etc/omarchy.conf ]]; then default_target="/usr/share/omarchy"
echo "Not currently linked. OMARCHY_PATH already resolves to /usr/share/omarchy." linked=0
exit 0 prior_target=""
if [[ -f /etc/omarchy.conf ]]; then
# Capture the path dev-link wrote BEFORE we reset the conf, so we know
# which bin/ to strip from PATH.
prior_target=$(sed -n 's/^[[:space:]]*export[[:space:]]\+OMARCHY_PATH="\?\([^"]*\)"\?/\1/p' /etc/omarchy.conf | tail -1)
if [[ $prior_target != "$default_target" ]]; then
linked=1
echo "Unlinking Omarchy from ${prior_target:-<empty>}"
else
echo "/etc/omarchy.conf already points at $default_target."
fi
elif [[ ${OMARCHY_PATH:-$default_target} != "$default_target" ]]; then
prior_target="$OMARCHY_PATH"
echo "Not currently linked: /etc/omarchy.conf is absent."
echo "This shell still has OMARCHY_PATH=$OMARCHY_PATH; writing the default guard."
else
echo "Not currently linked. Writing the default OMARCHY_PATH guard."
fi fi
# Capture the path dev-link wrote BEFORE we delete the conf, so we know printf 'export OMARCHY_PATH="%s"\n' "$default_target" | sudo tee /etc/omarchy.conf >/dev/null
# which bin/ to strip from PATH. echo "Set /etc/omarchy.conf -> OMARCHY_PATH=$default_target"
prior_target=$(sed -n 's/^[[:space:]]*export[[:space:]]\+OMARCHY_PATH="\?\([^"]*\)"\?/\1/p' /etc/omarchy.conf | tail -1)
sudo rm -f /etc/omarchy.conf
echo "Removed /etc/omarchy.conf"
export OMARCHY_PATH=/usr/share/omarchy export OMARCHY_PATH="$default_target"
if [[ -n $prior_target ]]; then if [[ -n $prior_target && $prior_target != "$default_target" ]]; then
PATH=$(printf '%s' "$PATH" | tr ':' '\n' | grep -vFx "$prior_target/bin" | paste -sd:) PATH=$(printf '%s' "$PATH" | tr ':' '\n' | awk -v drop="$prior_target/bin" '$0 != drop' | paste -sd:)
export PATH export PATH
fi fi
if command -v systemctl >/dev/null 2>&1; then
if systemctl --user import-environment OMARCHY_PATH PATH 2>/dev/null; then
echo " Updated systemd --user env."
fi
fi
if command -v hyprctl >/dev/null 2>&1 && hyprctl version &>/dev/null; then if command -v hyprctl >/dev/null 2>&1 && hyprctl version &>/dev/null; then
hyprctl setenv OMARCHY_PATH /usr/share/omarchy >/dev/null hyprctl setenv OMARCHY_PATH "$default_target" >/dev/null
hyprctl setenv PATH "$PATH" >/dev/null hyprctl setenv PATH "$PATH" >/dev/null
echo " Updated Hyprland session env." echo " Updated Hyprland session env."
systemctl --user import-environment OMARCHY_PATH PATH 2>/dev/null || true
echo " Updated systemd --user env."
if pgrep -x quickshell >/dev/null 2>&1; then if pgrep -x quickshell >/dev/null 2>&1; then
omarchy-restart-shell omarchy-restart-shell
echo " Restarted omarchy-shell." echo " Restarted omarchy-shell."
@@ -56,4 +74,9 @@ if command -v hyprctl >/dev/null 2>&1 && hyprctl version &>/dev/null; then
fi fi
echo echo
echo "Done. Existing shells still have the old OMARCHY_PATH until restarted." if (( linked )) || [[ -n $prior_target ]]; then
echo "Done. Existing shells still have the old OMARCHY_PATH until restarted."
echo "For this shell, run: export OMARCHY_PATH=$default_target"
else
echo "Done."
fi
+3 -2
View File
@@ -4,8 +4,9 @@
# /usr/share/uwsm/env.d/10-omarchy (Hyprland session via uwsm) # /usr/share/uwsm/env.d/10-omarchy (Hyprland session via uwsm)
# /usr/share/omarchy/default/bash/envs (bash rc chain; SSH/non-login) # /usr/share/omarchy/default/bash/envs (bash rc chain; SSH/non-login)
# /etc/omarchy.conf is written by omarchy-dev-link. When absent, force the # /etc/omarchy.conf is written by omarchy-dev-link and reset by
# packaged default instead of preserving a stale inherited value. # omarchy-dev-unlink. When absent, force the packaged default instead of
# preserving a stale inherited value.
if [ -f /etc/omarchy.conf ]; then if [ -f /etc/omarchy.conf ]; then
. /etc/omarchy.conf . /etc/omarchy.conf
: "${OMARCHY_PATH:=/usr/share/omarchy}" : "${OMARCHY_PATH:=/usr/share/omarchy}"
+1 -1
View File
@@ -4,7 +4,7 @@
local home = os.getenv("HOME") local home = os.getenv("HOME")
-- /etc/omarchy.conf wins over process env so dev-link survives stale sessions. -- /etc/omarchy.conf wins over process env so dev-link/unlink survives stale sessions.
local function read_dev_link_omarchy_path() local function read_dev_link_omarchy_path()
local f = io.open("/etc/omarchy.conf", "r") local f = io.open("/etc/omarchy.conf", "r")
if not f then return nil end if not f then return nil end
+4 -3
View File
@@ -129,9 +129,10 @@ upgrade. This is documented in the PKGBUILD.
Single source of truth for `OMARCHY_PATH` and dev-link-aware `PATH`. It: Single source of truth for `OMARCHY_PATH` and dev-link-aware `PATH`. It:
- Sources `/etc/omarchy.conf` (written by `omarchy-dev-link`) if present; - Sources `/etc/omarchy.conf` (written by `omarchy-dev-link`, reset to the
otherwise forces `OMARCHY_PATH=/usr/share/omarchy` so a stale inherited package path by `omarchy-dev-unlink`) if present; otherwise forces
value can't survive an `omarchy-dev-unlink`. `OMARCHY_PATH=/usr/share/omarchy` so a stale inherited value can't survive
an `omarchy-dev-unlink`.
- Prepends `$OMARCHY_PATH/bin` to `PATH` **only when** `OMARCHY_PATH` is - Prepends `$OMARCHY_PATH/bin` to `PATH` **only when** `OMARCHY_PATH` is
not `/usr/share/omarchy`. On a production install the binaries are not `/usr/share/omarchy`. On a production install the binaries are
already on `PATH` as `/usr/bin/omarchy-*` via the `omarchy` package. already on `PATH` as `/usr/bin/omarchy-*` via the `omarchy` package.