# If you use and like our software, please send us a postcard! ^^
#
# Copyright (C) 2009, 2010, Zhang Initiative Research Unit,
# Advance Science Institute, Riken
# 2-1 Hirosawa, Wako, Saitama 351-0198, Japan
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

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

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

# huge history
export HISTFILESIZE=10000
export HISTSIZE=10000

# don't put duplicate lines in the history.
export HISTCONTROL=ignoredups
# ... and ignore same sucessive entries.
export HISTCONTROL=ignoreboth

# color support of ls
if [ "$TERM" != "dumb" ] && [ -x /usr/bin/dircolors ]; then
    eval "`dircolors -b`"
    alias ls='ls --color=auto'
fi

alias ayssh='ssh -AY'
alias commit='svn commit'
alias countfiles='\ls -1 | wc -l'
alias enswitch='export LANG=en_US.UTF-8'
alias frswitch='export LANG=fr_FR.UTF-8'
alias gitpull='git pull'
alias gitpush='git push'
alias gitstat='git status'
alias htop='nice htop'
alias igrep='grep -i'
alias jpswitch='export LANG=ja_JP.UTF-8'
alias l='ls -lrt'
alias la='ls -la'
alias ll='ls -l'
alias lrt='ls -lrt'
alias mv='mv -i'
alias nwemacs='emacs -nw -bg black -fg white'
alias remake='make clean && make'
alias resource='source ~/.bashrc'
alias revert='svn revert'
alias rm='rm -i'
alias sc4='scons -j4'
alias sc5='scons -j5'
alias svndiff='svn diff --diff-cmd tkdiff'
alias svnstat='svn status | egrep -v "^\?"'
alias update='svn update'
alias yssh='ssh -Y'

# edit within a server emacs
function em () {
    emacsclient --no-wait $*
}

function colordiff () {
    svn diff $* | grep -v '^@@.*@@$' | vim -R -
}

function gitdiff() {
    bash -c "export GIT_EXTERNAL_DIFF=~/bin/tkdiff_git_wrapper.sh ; \
git diff $*"
}

# print line number n from file
# doesn't print anything if n is out of range
# n must be in [1; `wc -l file`]
# usage: getline n file
function getline () {
    awk -v LN=$1 '(NR==LN){print $0}' $2
}

export EDITOR="emacs -nw -bg black -fg white "
export PAGER=less

# svn side-by-side diff
function sbsdiff () {
    svn --diff-cmd "diff" \
--extensions "--suppress-common-lines -y --width=160" diff
}

# find here
function fh () {
    find . -name $*
}

export PYTHONSTARTUP=$HOME/.pystartup

function ccigrep () {
    grep -i $1 $(find . -name *.cc)
}

function cigrep () {
    grep -i $1 $(find . -name *.c)
}

function hhigrep () {
    grep -i $1 $(find . -name *.hh)
}

function higrep () {
    grep -i $1 $(find . -name *.h)
}

# shell colors
SH_COLOR_TXTBLK='\e[0;30m' # Black - Regular
SH_COLOR_TXTRED='\e[0;31m' # Red
SH_COLOR_TXTGRN='\e[0;32m' # Green
SH_COLOR_TXTYLW='\e[0;33m' # Yellow
SH_COLOR_TXTBLU='\e[0;34m' # Blue
SH_COLOR_TXTPUR='\e[0;35m' # Purple
SH_COLOR_TXTCYN='\e[0;36m' # Cyan
SH_COLOR_TXTWHT='\e[0;37m' # White
SH_COLOR_BLDBLK='\e[1;30m' # Black - Bold
SH_COLOR_BLDRED='\e[1;31m' # Red
SH_COLOR_BLDGRN='\e[1;32m' # Green
SH_COLOR_BLDYLW='\e[1;33m' # Yellow
SH_COLOR_BLDBLU='\e[1;34m' # Blue
SH_COLOR_BLDPUR='\e[1;35m' # Purple
SH_COLOR_BLDCYN='\e[1;36m' # Cyan
SH_COLOR_BLDWHT='\e[1;37m' # White
SH_COLOR_UNDBLK='\e[4;30m' # Black - Underline
SH_COLOR_UNDRED='\e[4;31m' # Red
SH_COLOR_UNDGRN='\e[4;32m' # Green
SH_COLOR_UNDYLW='\e[4;33m' # Yellow
SH_COLOR_UNDBLU='\e[4;34m' # Blue
SH_COLOR_UNDPUR='\e[4;35m' # Purple
SH_COLOR_UNDCYN='\e[4;36m' # Cyan
SH_COLOR_UNDWHT='\e[4;37m' # White
SH_COLOR_BAKBLK='\e[40m'   # Black - Background
SH_COLOR_BAKRED='\e[41m'   # Red
SH_COLOR_BAKGRN='\e[42m'   # Green
SH_COLOR_BAKYLW='\e[43m'   # Yellow
SH_COLOR_BAKBLU='\e[44m'   # Blue
SH_COLOR_BAKPUR='\e[45m'   # Purple
SH_COLOR_BAKCYN='\e[46m'   # Cyan
SH_COLOR_BAKWHT='\e[47m'   # White
SH_COLOR_TXTRST='\e[0m'    # Text Reset

export PS1="\[$SH_COLOR_TXTGRN\]\u\[$SH_COLOR_TXTWHT\]@\[$SH_COLOR_TXTGRN\]\h\[$SH_COLOR_TXTWHT\]:\[$SH_COLOR_TXTGRN\]\W\[$SH_COLOR_BLDRED\]# \[$SH_COLOR_TXTRST\]"

if [ -f ~/.Xresources ]; then
    xrdb ~/.Xresources
fi
