# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

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

# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
export HISTCONTROL=ignoredups

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=10000
HISTFILESIZE=20000

# 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, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

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

# Add an "alert" alias for long running commands.  Use like so:
#   sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi

unalias rm cp mv >& /dev/null
export PS1='\[\e[0;1;34m\][\t] \w\[\e[0;1;31m\]$\[\e[0m\]\n'

alias grep='grep --colour=auto'
alias ls='ls --color=auto'
alias lsd='ls -d `find -maxdepth 1 -type d -print | sed "s/^\.\///" | grep "[^\.]"`'
alias lsl='ls -l --color'
alias ssh='ssh -Y'
export PATH="$PATH:$HOME/bin"
export GIT_EDITOR=emacs
export EDITOR=emacs
export PHYSBAM_COMPILE_COUNT=16

# Change to "osx" if on mac.
export PLATFORM=linux
function set_pb() {
    local tmp_=$1
    if [ "$tmp_" = "" ] ; then
        tmp_=$PWD
        while ! [ -e "$tmp_"/Public_Library ] && [ "$tmp_" != "/" ] ; do
	    tmp_=`dirname "$tmp_"`
        done
    fi
    if [ -e "$tmp_"/Public_Library ] ; then
	echo "PhysBAM = $tmp_"
	export PHYSBAM="$tmp_"
	export PROJ="$PHYSBAM"/Projects
	export PUBLIC="$PHYSBAM"/Public_Library
	export PHYSBAM_DATA_DIRECTORY="$PHYSBAM"/Public_Data
    else
	echo "Could not find Public_Library"
	return 1
    fi
}
set_pb >/dev/null || set_pb $HOME/PhysBAM >/dev/null

alias o='$PHYSBAM/Projects/opengl_3d/opengl_3d$SUFFIX'
alias o2='$PHYSBAM/Projects/opengl_2d/opengl_2d$SUFFIX'
alias o3='$PHYSBAM/Projects/opengl_3d/opengl_3d$SUFFIX'
alias cs='nice scons --warn=no-duplicate-environment --warn=no-deprecated -Q --implicit-cache -u -j 16'
alias csd='cs TYPE=debug'
alias pb='cd $PHYSBAM'
alias pl='cd $PHYSBAM/Public_Library'
alias proj='cd $PHYSBAM/Projects'
alias gl='cd $PHYSBAM/Projects/opengl_3d'
alias gl2='cd $PHYSBAM/Projects/opengl_3d'
alias vg='$PHYSBAM/Tools/view_geometry/view_geometry'
alias tp='cd $PHYSBAM/Projects/test_proj'
function fixlink(){ ( proj ; cs -k 2>&1 | gen-instantiations.pl ) ; }
function findall() { grep "$1"  **/*.h  **/*.cpp ; }
function repall() { perl -npi -e "s@$1@$2@g" **/*.h **/*.cpp ; }
alias screen='screen -e "^oo"'
export PATH="$PATH:$PHYSBAM/Scripts/misc"
alias col="perl -e '"'while(<STDIN>){@A=split(/\s+/," $_");print "@A[@ARGV]\n"}'"'"

function make_mov()
{
    ~/bin/ffmpeg -y -i "$1" -pix_fmt yuv420p -vcodec libx264 -b 4096k "$2"
}

function svg-to-pdf()
{
    IN="$1"
    OUT="$2"
    [ "X$OUT" = "X" ] && OUT="${IN/svg/pdf}"
    [ "X$OUT" = "X$IN" ] || rsvg-convert -f pdf -o "$OUT" "$IN"
}

alias octave='octave --no-gui'
