export PATH="/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:${PATH}"
export LANG='en_US.UTF-8'
export PAGER='less -RF'

if [[ "$OSTYPE" =~ ^darwin ]]; then
	if [ -x /opt/homebrew/bin/brew ]; then
		eval "$(/opt/homebrew/bin/brew shellenv)"
	fi

	# Use GNU tools if they're installed :D
	for d in "${HOMEBREW_PREFIX}/opt"/*/libexec/gnubin; do
		export PATH="$d:$PATH"
	done

	for TEST_PATH in /Applications/Tailscale{.localized,}/Tailscale.app/Contents/MacOS/Tailscale; do
		if [ -x "$TEST_PATH" ]; then
			alias tailscale="$TEST_PATH"
			break
		fi
	done
fi

if command -v asdf &> /dev/null; then
	export PATH="${ASDF_DATA_DIR:-$HOME/.asdf}/shims:$PATH"

	if ! [ -r "${HOME}/.zcompletions/_asdf" ]; then
		asdf completion zsh > "${HOME}/.zcompletions/_asdf"
	fi
fi

for editor in nvim vim nano; do
    if command -v "$editor" &> /dev/null; then
        export EDITOR="$editor"
        break
    fi
done

if command -v rg &> /dev/null; then
	export RIPGREP_CONFIG_PATH="${HOME}/.config/ripgrep/ripgreprc"
fi

# if we're in vs code's terminal, set the editor to vs code
if [ "${TERM_PROGRAM:-noop}" = "vscode" ]; then
	if [[ "$TERM_PROGRAM_VERSION" =~ -insider$ ]] && command -v code-insiders &> /dev/null; then
		export EDITOR='code-insiders'
		alias code=code-insiders
	else
		export EDITOR='code'
	fi

	export TAG_CMD_FMT_STRING="${EDITOR} --goto {{.Filename}}:{{.LineNumber}}:{{.ColumnNumber}}"
fi

export VISUAL="${EDITOR}"

if [ -d "${HOME}/bin" ]; then
	export PATH="${HOME}/bin:${PATH}"
fi

if [ -d "${HOME}/.local/bin" ]; then
	export PATH="${HOME}/.local/bin:$PATH"
fi

if [ -d "${HOME}/.poetry/bin" ]; then
	export PATH="${HOME}/.poetry/bin:$PATH"
fi

. "$HOME/.cargo/env" 2>/dev/null

if command -v pnpm &> /dev/null; then
	if [[ "$OSTYPE" =~ ^darwin ]]; then
		export PNPM_HOME="${HOME}/Library/pnpm"
		export PATH="$PNPM_HOME:$PATH"
		mkdir -p "$PNPM_HOME"
	fi
fi

if command -v go &> /dev/null; then
	export GOPATH="${HOME}/.gopath"
	mkdir -p "${GOPATH}"
	export PATH="${GOPATH}/bin:${PATH}"
fi

if command -v lazygit &> /dev/null; then
	alias lg=lazygit
fi

. /etc/profile.d/flatpak.sh 2>/dev/null

# if rootless docker has a unix domain socket, use it!
if [ -e "${XDG_RUNTIME_DIR}/docker.sock" ]; then
	export DOCKER_HOST="unix://${XDG_RUNTIME_DIR}/docker.sock"
fi

if command -v fzf &> /dev/null; then
	if command -v rg &> /dev/null; then
		export FZF_DEFAULT_COMMAND="rg --files --hidden --follow --glob '!.git'"
	elif command -v ag &> /dev/null; then
		export FZF_DEFAULT_COMMAND='ag --skip-vcs-ignores --nocolor -g "" -l'
	fi

	if [ -n "${FZF_DEFAULT_COMMAND}" ]; then
		export FZF_CTRL_T_COMMAND="${FZF_DEFAULT_COMMAND}"
	fi
fi

if [ -r "${HOME}/.orbstack/shell/init.zsh" ]; then
	source ~/.orbstack/shell/init.zsh 2>/dev/null || :
fi

typeset -U path

# this is a hack to prevent MacOS from being smarter than us for PATH settings
/usr/libexec/path_helper() :