# My .bashrc file for interactive bash(1) shells.

# are we an interactive shell?
if [ "$PS1" ]; then

# Set a fancy prompt
# ******************

        # ** Generate short path
        # last two directories
        spwd () {
	  ( IFS=/
	    set $PWD
	    if test $# -le 3 ; then
		echo "$PWD"
	    else
		eval echo \"..\${$(($#-1))}/\${$#}\"
	    fi ) ; }
	# last 18 characters
	ppwd () {
 	    _w=`eval pwd`
	    _x="${_w//[^x]/x}"
	    test ${#_x} -le 18 || _w="..${_w:$((${#_x}-18))}"
            echo ${_w}
	    }
	
      # With full path (relative to home)
      export PS1='\[\e[1;32m\]\u@\h:\w\$\[\e[0m\] \[\e]2;\u@\h\a\e]30;\W\a\e[28;0t\]'
      # With short path (last 18)
#       export PS1="\[\033[34;1m\]\u@\h:\$(ppwd)\$\[\033[0m\] \[\e]2;\u@\h\a\e]30;\W\a\]"
      # With current directory
#       export PS1='\[\033[34;1m\]\u@\h:\W\$\[\033[0m\] \[\e]2;\u@\h\a\e]30;\W\a\]'
      # Only current directory, and number of line in history
#       export PS1='\[\033[34;1m\]\W \!$\[\033[0m\] \[\e]2;\u@\h\a\e]30;\W\a\]'
      
      # ** Explaining the prompts:
      # generally: \[<<control-sequence(s)>>\]
      #
      # \e[1;34m        -> set font color:
      #                      1; for bright  (0 would be dark)
      #                      34 for blue
      #                      could add ;40 for bg 40)
      #                  insert 0; o
      # \e[0m         -> set font back to defaults
      # \e]2;\u@\h\a  -> set window title to \u@\h (user@host)
      # \e]30;\W\a    -> set tab title to \W (name of dir we're in)
      # \e[28;0t      -> set tab color to defaults (black text)


# Colorful directory listings
# ***************************

    LS_OPTIONS="--color=auto"
    #eval "`dircolors -b /etc/bash.ls_colors`"
    alias ls="ls -h $LS_OPTIONS"


    
# Bash Completion, if available
# *****************************
    if [ -f /etc/bash_completion ]; then
        . /etc/bash_completion 
    fi
    
    _expand() {
      return 0
    }

# Alias definitions
# *****************

    # Sicherheit für gefährliche Befehle
    alias rm="rm -i"
    alias mv="mv -i"
    alias cp="cp -i"

    # weitere nuetzliche aliase
    alias cd..="cd .."
    alias ..="cd .."
    alias dir="ls -l | grep ^d"
    alias l="ls -l"
    alias ll="ls -Al"
    alias open="kde-open 2> /dev/null > /dev/null"
    #alias cal="ncal -M"

    # convert file-encoding
    function ic {
      cp $1 $1.iso
      iconv -f ISO-8859-1 -t UTF-8 $1 > $1.utf
      mv -f $1.utf $1
    }

    # display changelog for a package
    function changelog {
      case "$#" in
        "1") name="$1"
             debian="";;
        "2") name="$2"
             debian=".Debian";;
        *  ) echo "usage: changelog [-d] package"
             return;;
      esac
      path="/usr/share/doc/$name"
      if [ -e "$path" ]
      then
        vim $path/changelog$debian.gz
      else
        echo "$path does not exist!"
      fi
    }

    # ssh logins
    alias gridln="ssh -2Y nchiapol@grid-ln2.physik.uzh.ch"
    alias physik="ssh -2Y nchiapol@linux.physik.uzh.ch"
    alias lxplus="ssh -2Y nchiapol@lxplus.cern.ch"

    export SPINOR=spinor11.physik.uzh.ch

    # network
    alias eth0="sudo dhclient -v eth0"

    # root
    alias root="root -l"

# history configurations
# **********************
    
    # delete last entry from history
    function histrm {
      last=`history | tail -1 | tr -s [:blank:] "\t" | cut -f 2`
      history -d $last
    }

    # ignore dublicates, ignore commands starting with space
    export HISTCONTROL=erasedups:ignorespace
    # do not add these commands to the history
    export HISTIGNORE=history:histrm

# export environment variables
# ****************************
    source /home/nchiapol/downloads/root/bin/thisroot.sh
    export CPLUS_INCLUDE_PATH=/home/nchiapol/downloads/root/include
    export PYTHONSTARTUP=$HOME/.pystartup

fi
