#  ▄███████▄     ▄████████    ▄█    █▄
# ██▀     ▄██   ███    ███   ███    ███
#       ▄███▀   ███    █▀    ███    ███
#  ▀█▀▄███▀▄▄   ███         ▄███▄▄▄▄███▄▄
#   ▄███▀   ▀ ▀███████████ ▀▀███▀▀▀▀███▀
# ▄███▀                ███   ███    ███
# ███▄     ▄█    ▄█    ███   ███    ███
#  ▀████████▀  ▄████████▀    ███    █▀
#

export LANG="en_US.UTF-8"

# set XDG paths
export XDG_CACHE_HOME="${HOME}/.cache"
export XDG_DATA_HOME="${HOME}/.local/share"
export XDG_CONFIG_HOME="${HOME}/.config"

# load zinit
ZINIT_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}/zinit/zinit.git"
source "${ZINIT_HOME}/zinit.zsh"

# these must be here because otherwise mise packages will get pushed after brew (files
# are loaded in alphabetical order) - this is not ideal, but it's the best
# solution for now
# ===================================
# set homebrew on path (Intel)
export PATH="/usr/local/bin:$PATH"
# set homebrew on path (Apple Silicon) - should be first to override system bins
# (e.g. for updating zsh or bash)
export PATH="/opt/homebrew/bin:$PATH"
# ===================================

# mise global/local runtime version manager - must happen before all other tools
# are loaded since they may depend on it
eval "$(mise activate zsh)"

# load all config files
for f in ${XDG_CONFIG_HOME}/zsh/*; do
  source $f
done


ITERM2_INTEGRATION_SCRIPT="${HOME}/.iterm2_shell_integration.zsh"
test -e "$ITERM2_INTEGRATION_SCRIPT" && source "$ITERM2_INTEGRATION_SCRIPT"

# force delta pager even for small diffs
export GIT_PAGER=delta

# Preferred editor for local and remote sessions
if [ -z ${EDITOR+x} ]; then
  export EDITOR='nvim'
fi

# Editor for git commits, rebases etc (don't set it if it was set already...
# i.e. by NeoVim)
if [ -z ${GIT_EDITOR+x} ]; then
  export GIT_EDITOR='nvim'
fi

# ssh
export SSH_KEY_PATH="$HOME/.ssh/id_rsa"

# set cabal and haskell binaries on path
export PATH="$HOME/.cabal/bin:$HOME/.local/bin:$PATH"

# Golang
export PATH="/usr/local/go/bin:$PATH"

# dotfiles scripts
export PATH="$HOME/dotfiles/bin:$PATH"

# for android sdk (installed via homebrew)
export ANDROID_HOME=/usr/local/opt/android-sdk

if [[ -f ~/.ssh/id_rsa.pub ]]; then
  export SSH_FINGERPRINT=$(ssh-keygen -lf ~/.ssh/id_rsa.pub | awk '{print $2}')
fi

# tell RipGrep where to look for it's config file
export RIPGREP_CONFIG_PATH="$HOME/.config/ripgrep/config"

[[ -f ~/.zinitrc ]] && source ~/.zinitrc

# load aliases
[[ -f ~/.aliases ]] && source ~/.aliases

# Local config
[[ -f ~/.zshrc.local ]] && source ~/.zshrc.local

# add go path bin to path
export PATH=$PATH:$GOPATH/bin

# qt
case "$(uname -s)" in
  Darwin*)
    # don't mess with this.. or erlang will stop compiling.
    ;;
  Linux*)
    export PATH="/usr/local/opt/libpq/bin:$PATH"
    export PATH="/usr/local/opt/qt/bin:$PATH"
    export LDFLAGS="$LDFLAGS -L/usr/local/opt/qt/lib"
    export CPPFLAGS="-I/usr/local/opt/qt/include"
    ;;
esac

# OPEN SSL
# =====================================================

case "$(uname -s)" in
  Darwin*)
    # don't mess with this.. or erlang will stop compiling.
    ;;
  Linux*)
    export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"

    # For compilers to find openssl@1.1 you may need to set:
    export LDFLAGS="$LDFLAGS -L/usr/local/opt/openssl@1.1/lib"
    export CPPFLAGS="$CPPFLAGS -I/usr/local/opt/openssl@1.1/include"

    # For pkg-config to find openssl@1.1 you may need to set:
    export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"
    ;;
esac

export PATH="$HOME/.cargo/bin:$PATH"

# set up starship prompt
export STARSHIP_CONFIG="$HOME/.config/starship/config.toml"
eval "$(starship init zsh)"
