# Standard Bash environment for the GMN user

# If not running interactively, don't do anything
case $- in
  *i*) ;;
    *) return;;
esac

# Source global definitions
if [ -f /etc/bashrc ]; then
  . /etc/bashrc
fi

# Env

export D1_ROOT_DIR="/var/local/dataone"
export GMN_VENV_DIR="${D1_ROOT_DIR}/gmn_venv_py3"
export GMN_SITE_DIR=`${GMN_VENV_DIR}/bin/python -c "import site; print(site.getsitepackages()[0])"`
export GMN_PKG_DIR="${GMN_SITE_DIR}/d1_gmn"

# DataONE paths

function padd () {
  if [ -e "$1" ]; then
    echo "Adding to search path: $1"
    PATH="$1:$PATH"
  fi
}

echo
padd "${HOME}/bin"
padd "${GMN_VENV_DIR}/bin"
padd "${GMN_PKG_DIR}"

# Aliases

function alias_add () {
  echo "Adding alias: $1='$2'"
  alias $1="$2"
}

echo
alias_add "cdd1" "cd ${D1_ROOT_DIR}"
alias_add "cdgmn" "cd ${GMN_PKG_DIR}"
alias_add "clean-pyc" 'find . -name "*.pyc" -delete'

alias_add "ll" 'ls -l --group-directories-first --color'
alias_add "rs" 'rsync --recursive --verbose --progress --links --times'

alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'

echo
echo "- Using the GMN Python virtual environment by default (no need to activate venv)"
echo "- GMN venv: `which python`"
echo "- Added manage.py to the search path (no need to CD to d1_gmn package)"

# Colored GCC warnings and errors.
export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'

# Bash settings

# Group file sizes by thousand in coreutils (ls, du, etc)
export BLOCK_SIZE="'1"

# Prompt
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;33m\]\t\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

# History
# Don't put duplicate lines or lines starting with space in the history.
HISTCONTROL=ignoreboth:erasedups
# Append to the history file, don't overwrite it.
shopt -s histappend
# History length
HISTSIZE=1000
HISTFILESIZE=2000

# Check the window size after each command and, if necessary, update the values
# of LINES and COLUMNS.
shopt -s checkwinsize

# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
shopt -s globstar

# Make less more friendly for non-text input files.
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h \w\a\]$PS1"
    ;;
*)
    ;;
esac

echo
