#
# Executes commands at login pre-zshrc.
#
# Authors:
#   Sorin Ionescu <sorin.ionescu@gmail.com>
#

#
# Browser
#

# if [[ -z "$BROWSER" && "$OSTYPE" == darwin* ]]; then
#   export BROWSER='open'
# fi

#
# Editors
#

if [[ -z "$EDITOR" ]]; then
  export EDITOR='nvim'
fi
if [[ -z "$VISUAL" ]]; then
  export VISUAL='nvim'
fi
if [[ -z "$PAGER" ]]; then
  export PAGER='less -R'
fi

# BAT_PAGER does not work on OpenBSD right now...
# (displays nothing at all with this VARIABLE set)
if [[ -z "$BAT_PAGER" ]]; then
 export BAT_PAGER='less -R'
fi

#
# Language
#

if [[ -z "$LANG" ]]; then
  export LANG='de_AT.UTF-8'
fi

#
# Paths
#

# Ensure path arrays do not contain duplicates.
typeset -gU cdpath fpath mailpath path

# Set the list of directories that cd searches.
# cdpath=(
#   $cdpath
# )

# Set the list of directories that Zsh searches for programs.
path=(
  #$HOME/.local/share/gem/ruby/3.0.0/bin(N)
  #$HOME/.local/share/gem/ruby/3.2/bin(N)
  $HOME/.rvm/bin(N)
  $HOME/.cargo/bin(N)
  $HOME/go/bin(N)
  $HOME/.yarn/bin(N)
  $HOME/{,s}bin(N)
  $HOME/.local/{,s}bin(N)
  /usr/local/{,s}bin(N)
  $HOME/opt/qcad-3.31.1-pro-linux-qt5.14-x86_64(N)
  $path
)

[[ -d $HOME/go ]] && export GOPATH="${HOME}/go"
[[ -d ${GOPATH}/bin ]] && export GOBIN="${GOPATH}/bin"
[[ -d $HOME/.tmac ]] && export GROFF_TMAC_PATH="$HOME/.tmac"

# OpenBSD snapshots/current...
if [[ "$OSTYPE" == openbsd* ]]; then
  export PKG_PATH="http://mirror.hs-esslingen.de/pub/OpenBSD/snapshots/packages/amd64"
  #export PKG_PATH="http://ftp.nluug.nl/OpenBSD/snapshots/packages/amd64"
  export FETCH_CMD="/usr/local/bin/curl -L -s -q -N"
  export CVSROOT="anoncvs@ftp.hostserver.de:/cvs"
fi

# still here for reference, used to need that on KDE
# export SSH_ASKPASS='/usr/bin/ksshaskpass'

#
# Less
#

# Set the default Less options.
# Mouse-wheel scrolling has been disabled by -X (disable screen clearing).
# Remove -X to enable it.
if [[ -z "$LESS" ]]; then
  # export LESS='-R --use-color -Dd+r$Du+b$'
  # export LESS='-g -i -M -R -S -w -X -z-4'
  export LESS='-g -i -M -R -S -w -z-4'
fi

# export MANPAGER="sh -c 'col -b -x | bat -l man -p'"
# export MANROFFOPT="-c"

# OpenBSD grep does not want --color
# GREP_OPTS='--color=auto'      # for aliases since $GREP_OPTIONS is deprecated
# GREP_COLOR='1;32'             # (legacy) bright green rather than default red
# # (new) Matching text in Selected line = green, line numbers dark yellow
# GREP_COLORS="ms=${GREP_COLOR}:mc=${GREP_COLOR}:ln=33"
# alias grep='grep $GREP_OPTS'
# alias egrep='grep -E $GREP_OPTS'
# alias fgrep='LC_ALL=C grep -F $GREP_OPTS'

# Set the Less input preprocessor.
# Try both `lesspipe` and `lesspipe.sh` as either might exist on a system.
if [[ -z "$LESSOPEN" ]] && (( $#commands[(i)lesspipe(|.sh)] )); then
  export LESSOPEN="| /usr/bin/env $commands[(i)lesspipe(|.sh)] %s 2>&-"
fi