# Ensure XDG_CONFIG_HOME is set
: "${XDG_CONFIG_HOME:=$HOME/.config}"

# Set default pager
export PAGER="less -i -N -S -R"

# Ensure PYENV_ROOT is set and its bin directory is in PATH
if [ -n "$PYENV_ROOT" ] && [[ ! "$PATH" =~ (^|:)${PYENV_ROOT}/bin(:|$) ]]; then
  export PATH="$PYENV_ROOT/bin:$PATH"
fi
eval "$(pyenv init -)"

# Add ~/.local/bin to PATH if it exists
if [ -d "$HOME/.local/bin" ] && [[ ! "$PATH" =~ (^|:)${HOME}/.local/bin(:|$) ]]; then
  export PATH="$HOME/.local/bin:$PATH"
fi

# Set permissions for ~/.local/bin
chmod -R ug+rwx "$HOME/.local/bin/"

# Read fzf theme options if the file exists
if [ -f "$HOME/.local/bin/scripts/fzf_theme" ]; then
  FZF_OPTIONS=$("$HOME/.local/bin/scripts/fzf_theme")
  export FZF_DEFAULT_OPTS="$FZF_OPTIONS"
fi

# Source fzf configuration
if command -v fzf >/dev/null 2>&1; then
  eval "$(fzf --bash)"
fi

[ -f ~/.fzf.bash ] && . ~/.fzf.bash

# Add RVM to PATH
if [[ ! "$PATH" =~ (^|:)${HOME}/.rvm/bin(:|$) ]]; then
  export PATH="$PATH:$HOME/.rvm/bin"
fi

# Add Golang to PATH
if [ -n "$(go env GOPATH)" ] && [[ ! "$PATH" =~ (^|:)$(go env GOPATH)/bin(:|$) ]]; then
  export GOPATH="$HOME/Documents/projects:$HOME/go"
  export PATH="$PATH:$(go env GOPATH)/bin"
fi

# Cargo setup
if [ -d "$HOME/.cargo/bin" ] && [[ ! "$PATH" =~ (^|:)${HOME}/.cargo/bin(:|$) ]]; then
  export PATH="$HOME/.cargo/bin:$PATH"
fi

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/usr/local/Caskroom/miniforge/base/bin/conda' 'shell.bash' 'hook' 2>/dev/null)"
if [ $? -eq 0 ]; then
  eval "$__conda_setup"
else
  if [ -f "/usr/local/Caskroom/miniforge/base/etc/profile.d/conda.sh" ]; then
    . "/usr/local/Caskroom/miniforge/base/etc/profile.d/conda.sh"
  else
    export PATH="/usr/local/Caskroom/miniforge/base/bin:$PATH"
  fi
fi
unset __conda_setup
# <<< conda initialize <<<

