# This is a stripped-down version of the .bashrc file
# created and used by Stewart Weiss

# Many things in it are specific to the Hunter network
# but you can probably guess which they are
# Use at your own risk!

# Most systems have a global file that can be read
# before the user's local copy. In case there is one,
# the following lines source it, meaning read and execute
# its commands.
# Source global definitions from global bashrc file
if [ -f /etc/bashrc ]; then
   . /etc/bashrc
fi

# Get operating system name
sysname=`uname`

# Set up the cutomized prompt strings
unset PROMPT_COMMAND
# Primary prompt 
export PS1="[\u@\h \W]\$ "

# Secondary prompt 
export PS2="-> "

# Prompt 3 
export PS3="#? "

# Prompt 4 
export PS4="+"

# Command aliases 
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias ll='ls -l'
alias la='ls -a'

# On a Linux system, I use the additional aliases
if [ $sysname == 'Linux' ]; then
    alias ls='ls -F --color=tty' 2>/dev/null
    alias ll='ls -l -F --color=tty' 2>/dev/null
fi
alias l='less'
alias m='more'
alias h='history'
alias ..='cd ..'
alias back='cd $OLDPWD'
alias lo='logout'
alias cx='chmod +x '
alias psgrep="ps -ef | grep "
alias status='echo $?'

# eniac is the gateway to the Hunter CS network. The following
# is my lazy way to ssh into it, turning on X11 forwarding
alias eniac="ssh -X sweiss@eniac.cs.hunter.cuny.edu"

# A bunch of lazy ways to navigate to various directories
# They only exist on CS network, so make sure that is where we are
if [ `domainname` == huntercs ] ; then
    alias cs49370='cd /data/biocs/b/student.accounts/cs493.70'
    alias cs49366='cd /data/biocs/b/student.accounts/cs493.66'
    alias cs49365='cd /data/biocs/b/student.accounts/cs493.65'
    alias cs132='cd /data/biocs/b/student.accounts/cs132'
    alias cs135='cd /data/biocs/b/student.accounts/cs135_sw'
    alias cs235='cd /data/biocs/b/student.accounts/cs235_sw'
    alias cs335='cd /data/biocs/b/student.accounts/cs335_sw'
fi

# shred is a secure file removal function. I use wipe for it
alias wipe="shred --remove"

alias listips="sudo arp-scan --interface=eno1 --localnet"
alias ossd="cd ~/hunter/cs_ossd/"
alias vi >/dev/null 2>&1
if [ $? -eq 0 ]; then
    unalias vi
fi
alias psg="ps -o'%U %p %P %r %C %x %y %a' "
alias psgs="ps -ouser,pid,ppid,pgrp,sid,%cpu,cputime,tty,args"
alias man='LANG=C \man'
alias synchtime="ntpdate pool.ntp.org"

# Change the way globbing works so that invalid globs are 
# converted to null strings
shopt -s nullglob

# Command history 
export HISTFILE=~/.bash_history
export HISTCONTROL=ignoreboth
export HISTSIZE=500
export HISTFILESIZE=500
unset FCEDIT
export command_oriented_history=on
export histchars='!^#'

# Commandline 
set +o verbose
set +o xtrace
set -o ignoreeof
unset TMOUT
export EDITOR='vi'

# Completion 
set +o noglob
unset allow_null_glob_expansion
unset glob_dot_filenames

# Job control 
set -o monitor
unset auto_resume
set +b


# TTY appearance 
export COLUMNS=100
export LINES=24

# Error handling 
set +o nounset
unset no_exit_on_failed_exec
set +o errexit

# File/directory handling -- turn on noclobber
set -o noclobber
umask 022

# Set up PATHS
# Use pathmunge to avoid duplications and put paths in the best position
pathmunge () {
    if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then
       # the directory to be added is not already in PATH. Eureka!!!
       if [ "$2" = "after" ] ; then
          PATH=$PATH:$1
       else
          PATH=$1:$PATH
       fi
    fi
}

# Set up LIBRARY PATHS: Use pathmunge2 like pathmunge except for library paths
pathmunge2 () {
    if [ "$1" = "LP" ] ; then
        if ! echo $LIBRARY_PATH | /bin/egrep -q "(^|:)$2($|:)" ; then
           if [ "$3" = "after" ] ; then
              LIBRARY_PATH=$LIBRARY_PATH:$2
           else
              LIBRARY_PATH=$2:$LIBRARY_PATH
           fi
        fi
    else if [  "$1" = "LDP" ] ; then
            if ! echo $LD_LIBRARY_PATH | /bin/egrep -q "(^|:)$2($|:)" ; then
               if [ "$3" = "after" ] ; then
                  LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$2
               else
                  LD_LIBRARY_PATH=$2:$LD_LIBRARY_PATH
               fi
            fi 
        fi
    fi
}

pathmunge3 () {
if ! echo $MANPATH | /bin/egrep -q "(^|:)$1($|:)" ; then
   if [ "$2" = "after" ] ; then
      MANPATH=$MANPATH:$1
   else
      MANPATH=$1:$MANPATH
   fi
fi
}


if [ -e /usr/local/bin ]; then
    pathmunge /usr/local/bin 
fi

if [ -d /usr/sbin ]; then
    pathmunge /usr/sbin after
fi

if [ -e /usr/lib64/openmpi/bin ]; then
    pathmunge /usr/lib64/openmpi/bin after
fi

if [ -e /usr/ucb ]; then
    pathmunge /usr/ucb after
fi

if [ -d ~/bin ]; then
    pathmunge ~/bin after
fi

if [ -d /opt/firefox ]; then
    pathmunge /opt/firefox after
fi

if [ -e /opt/bin ]; then
    pathmunge /opt/bin after
fi


pathmunge . after


if [ -d /opt/apache-maven-3.3.9/bin ]; then
  pathmunge /opt/apache-maven-3.3.9/bin after
fi

# Add path for open source course executables
if [ -d ~/hunter/cs_ossd/cs395.86_s19/bin ] ; then
    pathmunge ~/hunter/cs_ossd/cs395.86_s19/bin  after
fi

PERL5LIB=$HOME/lib/perl5:/usr/local/share/perl5/Exporter:.
export PERL5LIB

pathmunge2 LDP ~/lib after
pathmunge2 LDP ~/unix_demos/lib  after
pathmunge2 LDP /usr/local/cuda/lib after
export LD_LIBRARY_PATH

pathmunge2 LP ~/lib/ after
pathmunge2 LP ~/unix_demos/lib  after
export LIBRARY_PATH



#CPATH=~/include:~/unix_demos/include
#export CPATH

# Environment variables for LaTeX and TeX
TEXINPUTS=".:$HOME/.lyx/includes::"


# Add path for manpages of MPI
if [ -e  /usr/share/man/openmpi-x86_64 ]; then
    pathmunge3 /usr/share/man/openmpi-x86_64 after
    export MANPATH
fi


LANG=en_US.UTF-8
export LANG

LC_CTYPE=en_US.UTF-8
export LC_CTYPE

GPG_TTY='tty'
export GPG_TTY


# fill in the line below with your GIT token if you have one
# or just comment it out
GIT_TOKEN=
export GIT_TOKEN

# Add  git completion tool support
  . ~/bin/git-completion.sh

# Add git prompt support
  . ~/bin/git-prompt.sh
  export GIT_PS1_SHOWDIRTYSTATE=1
  export GIT_PS1_SHOWSTASHSTATE=1
  export GIT_PS1_SHOWUNTRACKEDSTATE=1
# export PS1='\w$(__git_ps1 " (%s)")\$ '
export PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '