# Single source of truth for OMARCHY_PATH + PATH adjustments. Sourced by:
#   /etc/profile.d/omarchy.sh                 (system login shells)
#   /etc/skel/.bashrc                         (interactive shells)
#   /usr/share/uwsm/env.d/10-omarchy          (Hyprland session via uwsm)
#   /usr/share/omarchy/default/bash/envs      (bash rc chain; SSH/non-login)

# /etc/omarchy.conf is written by omarchy-dev-link and reset by
# omarchy-dev-unlink. When absent, force the packaged default instead of
# preserving a stale inherited value.
if [ -f /etc/omarchy.conf ]; then
  . /etc/omarchy.conf
  : "${OMARCHY_PATH:=/usr/share/omarchy}"
else
  OMARCHY_PATH=/usr/share/omarchy
fi
export OMARCHY_PATH

# Only prepend in dev-link mode. On a production install, the binaries are
# already on PATH as /usr/bin/omarchy-* via the omarchy package — prepending
# /usr/share/omarchy/bin would just be noise.
if [ "$OMARCHY_PATH" != /usr/share/omarchy ]; then
  case ":$PATH:" in
    *":${OMARCHY_PATH%/}/bin:"*) ;;
    *) PATH="${OMARCHY_PATH%/}/bin${PATH:+:$PATH}" ;;
  esac
fi

# User-level tool paths, appended so system binaries keep precedence. This is
# what lets login shells (ssh, bash -lc) and the uwsm session find mise-managed
# tools without an interactive rc. Keep these directories in sync with the PAM
# PATH line from install/config/ssh-command-path.sh, which covers SSH commands
# that run no shell setup at all.
#
# Based: the shims are the development backend's, mise's as upstream or asdf's
# when /etc/omarchy/dev-env-backend says asdf. Read here rather than through
# omarchy-dev-env-backend, which this file runs before PATH is settled.
omarchy_dev_env_backend=
if [ -r /etc/omarchy/dev-env-backend ]; then
  read -r omarchy_dev_env_backend </etc/omarchy/dev-env-backend || :
fi
if [ "$omarchy_dev_env_backend" = asdf ]; then
  omarchy_dev_env_shims=${ASDF_DATA_DIR:-$HOME/.asdf}/shims
else
  omarchy_dev_env_shims=$HOME/.local/share/mise/shims
fi
case ":$PATH:" in
  *":$omarchy_dev_env_shims:"*) ;;
  *) PATH="${PATH:+$PATH:}$omarchy_dev_env_shims" ;;
esac
unset omarchy_dev_env_backend omarchy_dev_env_shims
case ":$PATH:" in
  *":$HOME/.local/bin:"*) ;;
  *) PATH="${PATH:+$PATH:}$HOME/.local/bin" ;;
esac
export PATH
