# vim: set ft=sh:

# If not running interactively, don't do anything.
[[ $- != *i* ]] && return

# Source global definitions.
[[ -f /etc/bashrc ]] && source /etc/bashrc
[[ -f $HOME/.environ ]] && . $HOME/.environ

# Local user bins
add_path() case :$PATH: in *:$1:*) ;; *) PATH=$1:$PATH;; esac
add_path $HOME/.local/bin
add_path $HOME/.cargo/bin
add_path $HOME/.kubectl-plugins:$PATH
add_path $HOME/.tiup/bin
add_path $PYTHONUSERBASE/bin

# Append to history, don't overwrite.
shopt -s histappend

# Load customizations.
[[ -f $HOME/.bash_aliases ]] && source "$HOME/.bash_aliases"
[[ -f $HOME/.bash_colors ]] && source "$HOME/.bash_colors"
[[ -f $HOME/.bash_functions ]] && source "$HOME/.bash_functions"

# Save working dir on every prompt.
# export PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"; pwd > $HOME/.cwd'
export PS1="${Blue}\d \A ${Off}${Yellow}\u@\h: ${Off}\w ${Green}\$(parse_branch git)${BRed}\$(parse_branch fossil)${Off}\n-$ "

# more is less
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# Use fzf if installed.
hash fzf 2>/dev/null && eval "$(fzf --bash)"
export FZF_DEFAULT_OPTS='--border=horizontal --info=inline --no-reverse --height=50%'

# Use gpg-agent as ssh agent (and get a nice graphical prompt).
unset SSH_AGENT_PID
if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; then
    SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
    export SSH_AUTH_SOCK
fi
export GPG_TTY=$(tty)
gpg-connect-agent updatestartuptty /bye >/dev/null
