# vim: filetype=zsh

if [[ ! -d "${HISTFILE:h}" ]]; then
  mkdir -p "${HISTFILE:h}"
fi

add_path() {
  if [[ -d "$1" ]]; then
    path=("$1" $path)
  fi
}

set_include_lib_path() {
  # Fix für include/lib Verzeichnisse
  # Details: https://gcc.gnu.org/onlinedocs/cpp/Environment-Variables.html
  export C_INCLUDE_PATH="$1/include:$C_INCLUDE_PATH"
  export CPLUS_INCLUDE_PATH="$1/include:$CPLUS_INCLUDE_PATH"
  export LIBRARY_PATH="$1/lib:$LIBRARY_PATH"
}

add_path "$HOME/.cargo/bin"
add_path "$HOME/.local/bin"

case "$OSTYPE" in
  darwin*)
    add_path "/opt/homebrew/bin"

    set_include_lib_path "/opt/homebrew"
    ;;
  freebsd*)
    texlive_prefix="$HOME/.local/texlive"

    if [[ -d "$texlive_prefix/bin/amd64-freebsd" ]]; then
      add_path "$texlive_prefix/bin/amd64-freebsd"

      export MANPATH="${MANPATH:-$(manpath)}:$texlive_prefix/texmf-dist/man"
      export INFOPATH="${INFOPATH:+$INFOPATH:}$texlive_prefix/texmf-dist/info"
    fi

    set_include_lib_path "/usr/local"
    ;;
esac

# Fix Midnight Commander ESC Taste
# zusätzlich noch unter "F9 -> Optionen -> Konfiguration -> Escape Tastenmodus -> [x] Einzelner Tastendruck" aktivieren
export KEYBOARD_KEY_TIMEOUT_US=1000

# Tmuxp
# https://tmuxp.git-pull.com/configuration/environmental-variables.html
export TMUXP_CONFIGDIR="$XDG_CONFIG_HOME/tmuxp"

# Vit (Taskwarrior UI)
# https://github.com/vit-project/vit/blob/2.x/CUSTOMIZE.md
export VIT_DIR="$XDG_CONFIG_HOME/vit"

# Maildir für mu (mail-utils)
export MAILDIR="$HOME/Mail"

# mpd starten
if [[ -x /usr/local/bin/musicpd ]] && ! pgrep "musicpd" > /dev/null; then
  /usr/local/bin/musicpd
fi

unfunction add_path
unfunction set_include_lib_path
