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'

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

# if we're in vs code's terminal, set the editor to vs code
if [ "${TERM_PROGRAM:-noop}" = "vscode" ]; then
	export EDITOR='code'
	export TAG_CMD_FMT_STRING="code --goto {{.Filename}}:{{.LineNumber}}:{{.ColumnNumber}}"
fi

export VISUAL="${EDITOR}"

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 [ -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
	GOPATH="$(go env GOPATH)"
	if [ -d "${GOPATH}" ]; then
		export GOPATH
		export PATH="${GOPATH}/bin:${PATH}"
    else
        unset GOPATH
	fi
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 && command -v ag &> /dev/null; then
	export FZF_DEFAULT_COMMAND='ag --skip-vcs-ignores --nocolor -g "" -l'
	export FZF_CTRL_T_COMMAND="${FZF_DEFAULT_COMMAND}"
fi

typeset -U path

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