#!/bin/bash

# --- path ---
export PATH=~/bin:${ENVRCD_PROFILE_PATH}/bin:${PATH}

# --- git ---
if [ "${ENVRCD_USER}" == "rda" ]; then
    export GIT_AUTHOR_NAME='Sven Mäder'
    export GIT_AUTHOR_EMAIL='maeder@phys.ethz.ch'
    export GIT_COMMITTER_NAME="${GIT_AUTHOR_NAME}"
    export GIT_COMMITTER_EMAIL="${GIT_AUTHOR_EMAIL}"
fi

# --- debian packaging ---
if [ "${ENVRCD_USER}" == "rda" ]; then
    export DEBEMAIL="maeder@phys.ethz.ch"
    export DEBFULLNAME="Sven Mäder (rda)"
fi

# --- locale ---
export LANGUAGE=en
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8

# --- vim ---
export EDITOR=vim
# see: /usr/share/doc/vim/html/starting.html
# VIMINIT: list vim commands as in vimrc, separated by `|`
# source vimrc from cutom location during init
export VIMINIT="source ${ENVRCD_PROFILE_PATH}/.vimrc"
# MYVIMRC: is normally set to the location of the first found vimrc during init
# but when we use VIMINIT to source vimrc, we need to set it manually
export MYVIMRC="${ENVRCD_PROFILE_PATH}/.vimrc"
# alternative method, but better set MYVIMRC in shell env
#export VIMINIT="so ${ENVRCD_PROFILE_PATH}/.vimrc | let $MYVIMRC = '${ENVRCD_PROFILE_PATH}/.vimrc'"
# the vim path: /usr/share/vim
#export VIM='/usr/share/vim'
# profile specific `.vim` directory path for use in `.vimrc` in envrcd
export ENVRCD_VIM_PATH="${ENVRCD_PROFILE_PATH}/.vim"

# --- history ---
# ignore duplicates and commands beginning with whitespace
export HISTCONTROL=ignoreboth
# lines of history to store in memory
export HISTSIZE=4000
# truncate history file to this size
export HISTFILESIZE=4000
# ignore these commands for history
export HISTIGNORE="gits:gita:gitd:gitds:gitpr:git push"
# save timestamps
export HISTTIMEFORMAT="%FT%T%z  "

# --- pager ---
export PAGER='less -s'
export LESSCHARSET='utf-8'

# --- less ---
# enable raw control chars, only page if it does not fit into window
export LESS="-R -F -X ${LESS}"

# --- colorful less and man ---
# Attribute:    # 00=none 01=bold 04=underline 05=blink 07=reverse 08=concealed
# Text:         # 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
# Background:   # 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
export LESS_TERMCAP_mb=$'\e[1;32m'  # blink: bold green
export LESS_TERMCAP_md=$'\e[1;32m'  # bold: bold green
export LESS_TERMCAP_me=$'\e[0m'     # reset
export LESS_TERMCAP_so=$'\e[1;31m'  # standout: red
export LESS_TERMCAP_se=$'\e[0m'     # reset
export LESS_TERMCAP_us=$'\e[1;34m'  # underline: bold blue
export LESS_TERMCAP_ue=$'\e[0m'     # reset
export GROFF_NO_SGR=1               # for console and gnome-terminal

#export LESS="--RAW-CONTROL-CHARS"
#export LESS_TERMCAP_mb=$(tput bold; tput setaf 2)  # blink: bold green
#export LESS_TERMCAP_md=$(tput bold; tput setaf 2)  # bold: bold green
#export LESS_TERMCAP_me=$(tput sgr0)                # reset
#export LESS_TERMCAP_so=$(tput bold; tput setaf 1)  # standout: red
#export LESS_TERMCAP_se=$(tput sgr0)                # reset
#export LESS_TERMCAP_us=$(tput bold; tput setaf 4)  # underline: bold blue
#export LESS_TERMCAP_ue=$(tput sgr0)                # reset
#export GROFF_NO_SGR=1                              # for console and gnome-terminal

# --- gui ---
export QT_QPA_PLATFORMTHEME=gtk2

# --- grep ---
export GREP_COLORS='ms=01;31:mc=01;31:sl=:cx=:fn=33:ln=32:bn=32:se=36'

# --- bat ---
export BAT_THEME='DarkNeon'

# --- xdg ---
# is not set at all by default, possibly breaks things?
#export XDG_CONFIG_HOME="${ENVRCD_PROFILE_PATH}/.config"

# --- ansible ---
if [ "${ENVRCD_USER}" == "rda" ] && [ "${USER}" == "maedersv" ]; then
    #export ANSIBLE_CONFIG="~/.ansible.cfg"
    if [ -d "$HOME/.local/bin" ]; then
        export PATH="${HOME}/.local/bin:${PATH}"
    fi
    export ANSIBLE_STRATEGY_PLUGINS="~/.ansible/mitogen/ansible_mitogen/plugins/strategy"
    export ANSIBLE_STRATEGY="mitogen_linear"
    export ANSIBLE_ISG_PHYS_PATH="~/git/ansible-isg-phys"
    export ANSIBLE_VAULT_ID_MATCH=true
    export ANSIBLE_VAULT_IDENTITY_LIST="production@${ANSIBLE_ISG_PHYS_PATH}/.vault-keys/production,workstations@${ANSIBLE_ISG_PHYS_PATH}/.vault-keys/workstations,testing@${ANSIBLE_ISG_PHYS_PATH}/.vault-keys/testing"
fi

# --- keychain (ssh-agent, gpg-agent) ---
if [ "${ENVRCD_USER}" == "rda" ] && [ "${HOSTNAME}" == "rda" ] && [ "${USER}" == "maedersv" ]; then
    eval $(keychain --nogui --eval --ignore-missing --noinherit --quiet --noask --agents ssh,gpg --quick id_ed25519 id_rsa 8F3FB7BD7A6BF71D)
fi