# Editor used by CLI
export EDITOR="${EDITOR:-omarchy-launch-editor --inline}"
export SUDO_EDITOR="$EDITOR"

# Used by terminal programs (like gh) to open URLs detached from the terminal
# process tree. Shell-scoped on purpose: exporting BROWSER session-wide makes
# xdg-settings refuse to change the default browser.
export BROWSER="${BROWSER:-omarchy-launch-browser}"
export BAT_THEME=ansi

# Color man pages with bat
export MANROFFOPT="-c"
export MANPAGER="sh -c 'col -bx | bat -l man -p'"

# Idempotent — already sourced by /etc/skel/.bashrc; re-source here only when
# this shell hasn't run it yet (e.g. SSH or non-interactive non-login bash).
if [ -z "${_OMARCHY_ENV_BOOTSTRAPPED:-}" ] && [ -r /usr/share/omarchy/default/bash/env-bootstrap ]; then
  . /usr/share/omarchy/default/bash/env-bootstrap
fi

# /etc/profile.d/locale.sh is what puts /etc/locale.conf into the environment,
# and it only runs for login shells. Bash started by SSH or herdr's remote
# bridge misses it and lands in the C locale, where printf emits \u/\U escapes
# literally instead of the character. Mirror locale.sh for those sessions.
if [ -z "${LANG:-}" ]; then
  [ -r /etc/locale.conf ] && . /etc/locale.conf
  LANG="${LANG:-C.UTF-8}"
  export LANG LANGUAGE LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY \
    LC_MESSAGES LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT \
    LC_IDENTIFICATION
fi

# A herdr server started over SSH has no WAYLAND_DISPLAY, so its panes can't
# read the desktop clipboard once you attach locally. Inherit the live graphical
# session's Wayland display inside herdr panes without exporting it to plain
# SSH sessions (where omarchy-launch-editor falls back to vi).
if [[ ${HERDR_ENV:-} == 1 && -z ${WAYLAND_DISPLAY:-} ]]; then
  _omarchy_wayland=$(systemctl --user show-environment 2>/dev/null | sed -n 's/^WAYLAND_DISPLAY=//p')
  [[ -n $_omarchy_wayland && -S ${XDG_RUNTIME_DIR:-/run/user/$UID}/$_omarchy_wayland ]] && export WAYLAND_DISPLAY=$_omarchy_wayland
  unset _omarchy_wayland
fi

case ":$PATH:" in
  *":$HOME/.local/bin:"*) ;;
  *) export PATH="$PATH:$HOME/.local/bin" ;;
esac
