##################################################
# ~/.bashrc
# $Id: bashrc 3 2005-03-29 07:36:42Z pfeifer $
# Hagen Paul Pfeifer - hagen@jauu.net
# http://www.jauu.net
#
##################################################

# return if ! interactively
[ -z "$PS1" ] && return

##################################################
# common stuff goes here


# Define some colors:
red='\e[0;31m'
RED='\e[1;31m'
blue='\e[0;34m'
BLUE='\e[1;34m'
cyan='\e[0;36m'
CYAN='\e[1;36m'
NC='\e[0m'

### check for OS
case $(uname -s) in
  Linux)
    OS="linux"
    alias psa='ps axo "user,pid,ppid,%cpu,%mem,tty,stime,state,command"'
    # 0x20C3F4DD is my certification only key 
    alias gpgsign='gpg -u 20C3F4DD --sign-key'
  ;;
  *[bB][Ss][Dd])
    OS="bsd"
    alias psa='ps axo "user,pid,ppid,%cpu,%mem,tty,start,state,command"'
  ;;
  *)
    OS="unknown"
  ;;
esac

### check for DIST
if [ -f /etc/redhat-release ]; then
  DIST="redhat"
elif [ -f /etc/gentoo-release ] || [ -f /usr/bin/emerge ]; then
  DIST="gentoo"
fi

case "${DIST}" in

  gentoo)
    #if [ -f /etc/profile.d/bash-completion ]; then 
    #    source /etc/profile.d/bash-completion
    #fi
  ;;

  *)
  ;;
esac

### check for DOMAINNAME
DOMAINNAME=$(dnsdomainname 2>/dev/null || hostname -d)
case "${DOMAINNAME}" in

   furcht.bar*)
     export CFLAGS="-O3 -fomit-frame-pointer -pipe";
     export CXXFLAGS=$CFLAGS;
   ;;
   fh-furtwangen.de*)
     # news server
     export NNTPSERVER=news.ai-lab.fh-furtwangen.de
     export CFLAGS="-march=i386 -Os -fomit-frame-pointer -pipe";
     export CXXFLAGS=$CFLAGS;

     alias  clearcash="rm -rf ~/.firefox/default/71uumtop.slt/Cache/*"
   ;;

   *)
   ;;
esac

### check for HOSTNAME
HOSTNAME=$(hostname 2>/dev/null || hostname -f)
case "${HOSTNAME}" in

   einstein*,bacon,euler*)
     export CFLAGS="-march=i386 -Os -fomit-frame-pointer -pipe";
     export CXXFLAGS=$CFLAGS;
   ;;

   *)
   ;;
esac

# terminal spezific stuff
case "$TERM" in
xterm*|rxvt*)
    # If this is an xterm set the title to user@host:dir
    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
    ;;
*)
    ;;
esac

#############################################################################
# PERSONAL STUFF

# cfs-envs
export CVSROOT=/home/cvs/cvsrep
export CVSUMASK=003
export CVSEDITOR=vim

# save umask rw-r--r--
umask 022
# of course
export EDITOR='/usr/bin/vim'
# favorite pager (give more information)
export PAGER='/usr/bin/less'
# less options via env
export LESS="--force --ignore-case -M"
# Immediate background job termination notification
set -b

# classpath for java libaries
export CLASSPATH=.:${CLASSPATH}

# default encrypted session via rsync
export RSYNC_RSH=ssh

# misc
export cur_tty=$(tty | sed -e "s/.*\/\(.*\)/\1/")
# 
# executable directories
export PATH=$HOME/bin:/sbin:${PATH}
export MOZILLA_HOME=$HOME/.mozilla
export PS1='\[\033[01;34m\]\!,$cur_tty,$?,\[\033[01;33m\]\W\[\033[01;34m\],\[\033[01;32m\]\$ \[\033[00m\]'

export QTDIR=/usr/lib/qt2
unset ROOTPATH


# add another prompt for remote connection (hostname || tty)
if test -z $SSH_TTY
then
  export PS1='\[\033[01;34m\]\!,$cur_tty,$?,\[\033[01;33m\]\W\[\033[01;34m\],\[\033[01;32m\] \$ \[\033[00m\]'
else
  export PS1='\[\033[01;34m\]\!,\h,$?,\[\033[01;33m\]\W\[\033[01;34m\],\[\033[01;32m\] \$ \[\033[00m\]'
fi

# progs env
export TCGREP="irnH"

HISTCONTROL=ignoreboth
HISTCONTROL=$HISTCONTROL # bug in shell ...
HISTFILESIZE=999
HISTSIZE=999
#HISTIGNORE=ls:ll:cd:pwd:exit:vim:clear:df:su:make:rm:cp:..:...

export HISTCONTROL HISTIGNORE

# colors for ls, etc.
if [ -f ${HOME}/.dir_colors ]
then
    eval `dircolors -b ${HOME}/.dir_colors`
elif [ -t /etc/DIR_COLORS ]
then
    eval `dircolors -b /etc/DIR_COLORS`
fi

[ -x /usr/bin/lesspipe ] && eval "$(lesspipe)"

# Language Stuff
# english messages && time, eur support
export LANGUAGE=C
export LANG=C
export LC_MESSAGES=C
export LC_TIME=C


# if you don't like underlining (or non-supporting)
# then you can do something like:
# setterm -ulcolor green

## Aliases
# don't print copyright messages at startup
alias gdb="gdb -silent"
# compress and X forward (see ~/.ssh/config)
#alias ssh="ssh -C -X"
# verbose remove force
alias shred="shred -v -u -f"
# use gnu style (default)
alias indent="indent --gnu-style"
# sort symbols numerically by their addresses
alias nm="nm -n"
#  verbose  mode
alias fuser="fuser -v"
alias d="ls --color"
alias ls="ls --color=auto"
alias la="ls --color=auto -al"
alias ll="ls --color -l"
alias rm="rm -if"
alias ..="cd .."
alias ...="cd .. ; cd .."
alias l.="ls -d .[A-Za-z]* --color=auto"
alias mkernel24='time make dep clean bzImage modules modules_install && date'
alias mkernel26='time make V=1 modules_install && date'
alias tutime='telnet time.fu-berlin.de 13 | grep :'
alias rsync='rsync -P --checksum'
alias s="sudo"

# change current permissions for home directory
alias homeopen="chmod -R go=rX $HOME"
alias homeclose="chmod -R go= $HOME"

# test if X is up and start links if possile with X support
if test ! -z $XAUTHORITY
then
  alias links='links -driver x'
fi

# found at ... (sorry forgoten!)
function __edit_new_script () {
   text="$1"; shift
   for i in ${@}; do
     [ ! -e "$i" ] && echo -e "$text" > "$i"
     chmod u+x $i
   done
   eval vim +$(echo -e "$text" | wc -l) "$@"
}

alias vish='__edit_new_script "#!/bin/bash\n\n"'
alias vipl='__edit_new_script "#!/usr/bin/perl -w\n\nuse strict;\n\n"'
alias vihtml="__edit_new_script '<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n\t\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html>\n<head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />\n  <title>\n\n </title>\n</head>\n<body>\n\n</body>\n</html>'"


#############################################################################
# FUNCTIONS

# programing environments
function env_koctopus
{
  export CVS_RSH=ssh
  export ENVURL=http://kocotpus.sourceforge.net/
}

# display fortune cookies via osd_cat
function osdfortune
{
  local PRLPTH="/usr/bin/perl"
  local FORTUNEPATH="/usr/bin/fortune"
  local OSDCATPATH="/usr/bin/osd_cat"
  local OSDCOLOR="red"
  local FONTSIZE="240"

  if ! [ -x ${OSDCATPATH} ] && ! [ -x ${FORTUNEPATH} ] &&
     ! [ -x ${PRLPTH} ]
  then
    echo "Install osdcat and fortunes && set current paths!";
  fi;

  ${FORTUNEPATH} -s                               | \
  ${PRLPTH} -MText::Wrap -e'use Text::Wrap;undef $/;$_=<>;exit()if(length>160);
  $Text::Wrap::columns=30;print fill("","",$_)'   | \
  ${OSDCATPATH} -p bottom -A center -c ${OSDCOLOR} \
#-l 30 -f -dec-terminal-medium-r-normal-*-*-${FONTSIZE}-*-*-c-${FONTSIZE}-*-1
    -l 30 -f -*-*-*-*-*-*-*-${FONTSIZE}-*-*-*-${FONTSIZE}-*-*

}

# ls && number of entrys
function lf
{
    ls --color=tty --classify $*
    echo "$(ls -l $* | wc -l) files"
}

# get current host related info
function ii
{
echo -e "\nYou are logged on ${RED}$HOST"
echo -e "\nAdditionnal information:$NC " ; uname -a
echo -e "\n${RED}Users logged on:$NC " ; w -h
echo -e "\n${RED}Current date :$NC " ; date
echo -e "\n${RED}Machine stats :$NC " ; uptime
echo -e "\n${RED}Memory stats :$NC " ; free
echo
}

# clear trash in history
function clearhist
{
cp ~/.bash_history ~/.bash_history.awkbak

awk '!/^(\ *)(dir|ls .*|valgrind .*|gdb .*|objdump .*|ls|cd .*|rm .*\
     |cat .*|beep .*|man .*|indent .*|cp .*|gcc.*|vim.*|clear.*|find.*|grep.*)(\ *)$/{
     sub(/\ *$/,"");
     lines[++count] = $0
     data[$0] = count
     }

END {
     for (i = 1; i <= count; i++)
     if (data[lines[i]] == i)
     print lines[i]
     }' ~/.bash_history > ~/.bash_history_temporary

mv ~/.bash_history_temporary ~/.bash_history
}

# look for definitions
function jargon
{
  BROWSER="links"
    JARGON_URL="http://info.astrian.net/jargon/terms"
  for i in ${*}; do
    ${BROWSER} ${JARGON_URL}/${i}.html
  done
}

# vim:set ts=2 tw=80 ft=sh: