##############################
# User specified file for configuring BASH.
# Author: Chris Jones
# Contact: @truckmonth <- twitter
# Contact: chris.r.jones.1983@gmail.com <- email
# Contact: @ipatch <- github
##

# test if `~/.bashrc` exists, and if so load it in the current bash env
if [ -f "$HOME/.bashrc" ]; then
	source "$HOME/.bashrc"
fi

# test if `~/.profile` exsits, then load it
if [ -f "$HOME/.profile" ]; then 
	source "$HOME/.profile"
fi

# test for `rvm` with `~/.rvm/scripts/rvm` then load
if [ -f "$HOME/.rvm/scripts/rvm" ]; then
	source "$HOME/.rvm/scripts/rvm"
fi

# set the size of the command history in bytes
HISTSIZE=1000000 # 1 Megabyte a.k.a 1MB

# test for git completions and git prompt
# OS=$(uname)
# if [[ $OS == Darwin ]]; then
# 	if [ -f "/Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-completion.bash" ]; then
#   source "/Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-completion.bash"
#   	fi
#   	if [ -f "/Applications/Xcode.app/Contents/Develper/usr/share/git-core/git-prompt.sh" ]; then
#   source "/Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-prompt.sh"
# 	fi

	# TODO: figure out why below 2 env vars were not loading properly
  #GIT_PS1_SHOWDIRTYSTATE=true;

  #PS1='\[\033[32m\]\u@\h\[\033[00m\]:\[\033[34m\]\w\[\033[31m\]$(__git_ps1)\[\033[00m\]\$ ';

# fi


# 💳 https://stackoverflow.com/a/18915067/708807

SSH_ENV="$HOME/.ssh/environment"

function start_agent {
    echo "Initialising new SSH agent..."
    /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
    echo succeeded
    chmod 600 "${SSH_ENV}"
    . "${SSH_ENV}" > /dev/null
    /usr/bin/ssh-add;
}

# Source SSH settings, if applicable

if [ -f "${SSH_ENV}" ]; then
    . "${SSH_ENV}" > /dev/null
    #ps ${SSH_AGENT_PID} doesn't work under cywgin
    ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
        start_agent;
    }
else
    start_agent;
fi

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/Users/capin/miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/Users/capin/miniconda3/etc/profile.d/conda.sh" ]; then
        . "/Users/capin/miniconda3/etc/profile.d/conda.sh"
    else
        export PATH="/Users/capin/miniconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<

