# .bashrc
# Author: jukka<dot>lankinen<at>gmail<dot>com
# Last Edited: 6.03.2012
#
# Description:  
#    Changes the prompt, adds aliases, colorizes all output and includes shell
#    completion. Additionally it does many other useful things.
#

# Check for an interactive session
[ -z "$PS1" ] && return
shopt -s checkwinsize
# disable control echo ^C
stty -ctlecho

# I want to see some fortune
# command fortune

# Prompt
#PS1='[\[\e[0;32m\]\u\[\e[m\]@\[\e[0;32m\]\h\[\e[m\]:\[\e[1;34m\]\w\[\e[m\]\[\e[m\]\[\e[1;32m\]\[\e[m\]] \[\e[m\]\[\e[1;37m\]' # Local
PS1='\[\e[m\]\[\e[1;32m\][\[\e[1;34m\]\w\[\e[m\]\[\e[1;32m\]] \[\e[m\]\[\e[1;37m\]' # Local
#PS1='[\[\e[1;31m\]\u\[\e[m\]@\[\e[1;31m\]\h\[\e[m\]:\[\e[1;34m\]\w\[\e[m\]\[\e[1;32m\]\[\e[m\]] \[\e[m\]\[\e[1;37m\]' # Others

# Aliases
if [ -n "$DISPLAY" ]
then
    export EDITOR='gvim --nofork'
else
    export EDITOR=vim
fi

export SHELL=/bin/bash
export VISUAL=$EDITOR
if [ "$TERM" != "dumb" ]; then
	
	# Colorize and humanize
	alias ls='ls --color=auto --time-style=long-iso -h'
	eval `dircolors -b`
	#alias diff='colordiff'
	#alias diff='vimdiff'
	alias grep='grep --color=auto'
	export GREP_COLOR="1;33"
	
	# Colorize svn diff
	svndiff()
	{
		svn diff "${@}" | colordiff
	}

fi

alias top='htop'
#alias nano='nano -wcxO' # use -i for auto-indenting
alias ll="ls -lh"
alias la="ls -a"
alias exit="clear; exit"

# Source global definitions
if [ -f /etc/bashrc ]; then
    . /etc/bashrc
fi
# Shell auto completion
# See .inputrc
if [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
fi

# History search
set show-all-if-ambiguous on # make it fast
HISTCONTROL=ignoredups:ignorespace
HISTCONTROL=ignoreboth
HISTSIZE=1000
HISTFILESIZE=2000

# Append to hist
shopt -s histappend
# fix directories
fixperm ()
{
	find * -type d -print0 | xargs -0 chmod 0755 # for directories
	find . -type f -print0 | xargs -0 chmod 0644 # for files
}

# extract with correct tool automagically
extract () 
{
	if [ -f $1 ] ; then
		case $1 in
			*.tar.bz2)   tar xvjf $1    ;;
			*.tar.xz)    tar xvJf $1    ;;
			*.tar.gz)    tar xvzf $1    ;;
			*.bz2)       bunzip2 $1     ;;
			*.rar)       unrar x $1     ;;
			*.gz)        gunzip $1      ;;
			*.tar)       tar xvf $1     ;;
			*.tbz2)      tar xvjf $1    ;;
			*.tgz)       tar xvzf $1    ;;
			*.zip)       unzip $1       ;;
			*.Z)         uncompress $1  ;;
			*.7z)        7z x $1        ;;
			*)           echo "don't know how to extract '$1'..." ;;
		esac
		else
			echo "'$1' is not a valid file!"
	fi
}

# END

###
# Optional but cool
#
# HTTP PROXY
# export http_proxy="http://www-cache.lut.fi:8080"
# ITLABCPP
# export LD_LIBRARY_PATH=/home/julankin/Work/Research/svn/itlabcpp/trunk/base/lib
# CVS
# export CVSROOT=":pserver:julankin@regulus.it.lut.fi:/net/regulus/project/cvsroot"
# export CVSROOT=":pserver:julankin@www2.it.lut.fi:/srv/cvsroot"

pacs() {
	local CL='\\e['
	local RS='\\e[0;0m'

	echo -e "$(pacman -Ss "$@" | sed "
		/^core/		s,.*,${CL}1;31m&${RS},
		/^extra/	s,.*,${CL}0;32m&${RS},
		/^community/	s,.*,${CL}1;35m&${RS},
		/^[^[:space:]]/	s,.*,${CL}0;36m&${RS},
	")"
}
aursearch() {
	#OUTPUT=$(cower --format "%n %o" -s "$1" | grep "$1" | grep -v extension | sort -nrk 2 | column -t | head -n 10)
	OUTPUT=$(cower --format "%n %o" -s "$1" | grep "$1" | grep -v extension | sort -nrk 2)
	echo -e "Package Votes\n$OUTPUT" | column -t
}

alias win='rdesktop -g 1280x960 -k fi -d LUT rdesktop.win.lut.fi'
alias pwi='WINEDEBUG=-all WINEPREFIX="/home/lanxu/Pelit/Wine/PWI" wine "C:\\Perfect World Entertainment\\Perfect World International\\launcher\\launcher.exe"'
alias cdmine='cd ~/Asiakirjat/Work/github/minetest'
alias pena2sshmysqltunnel='ssh -N -p 26 lanxu@pena2.dy.fi -L 3306:localhost:3306'
alias fixsteam='find ~/.steam/root/ \( -name "libgcc_s.so*" -o -name "libstdc++.so*" -o -name "libxcb.so*" \) -print -delete'
alias steamgamesdir='cd ~/.local/share/Steam/SteamApps/common'
export WINEARCH=win32

# Add environment variable COCOS_CONSOLE_ROOT for cocos2d-x
export COCOS_CONSOLE_ROOT=/home/lanxu/Sovellukset/cocos2d-js-v3.6.1/tools/cocos2d-console/bin
export IONIC_INSTALL=/home/lanxu/Asiakirjat/Work/Android/ionic/node_modules/.bin
export PATH=$IONIC_INSTALL:$COCOS_CONSOLE_ROOT:$PATH

# NPM no sudo
# https://github.com/sindresorhus/guides/blob/master/npm-global-without-sudo.md
NPM_PACKAGES="${HOME}/.npm-packages"
NODE_PATH="$NPM_PACKAGES/lib/node_modules:$NODE_PATH"
PATH="$NPM_PACKAGES/bin:$PATH"
# Unset manpath so we can inherit from /etc/manpath via the `manpath`
# command
unset MANPATH # delete if you already modified MANPATH elsewhere in your config
MANPATH="$NPM_PACKAGES/share/man:$(manpath)"
