##################################################
# ~/.zshrc
# $Id: zshrc 2 2005-03-29 07:22:59Z pfeifer $
# Hagen Paul Pfeifer - hagen@jauu.net
# http://www.jauu.net
#
##################################################


# core dumps up to 10000 blocks
ulimit -c 10000

# file creation mask
umask 022

## ENV's

# cvs-envs
export CVSUMASK=003
export CVSEDITOR=vim

# executable directories
export PATH=$HOME/bin:/sbin:${PATH}
export MOZILLA_HOME=$HOME/.mozilla
# newsserver
export NNTPSERVER=news.t-online.de

export PAGER="col -b | view -c 'set nomod' -"
export MANPAGER="col -b | view -c 'hi StatusLine ctermbg=green| set ft=man nomod nolist' -"

export TCGREP="irnH"

# less options via env
export LESS="--force --ignore-case -M"

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

# default encrypted session via rsync
export RSYNC_RSH=ssh

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


## ALIASES

# some piping stuff
alias -g V='|vim'
alias -g L='|less'
alias -g H='|head'
alias -g T='|tail'
alias -g G='|grep'
# for ^x^h
alias run-help='man'
# don't print copyright messages at startup
alias gdb="gdb -silent"
# verbose remove force
alias shred="shred -v -u -f"
# sort symbols numerically by their addresses
alias nm="nm -n"
#  verbose  mode
alias fuser="fuser -v"
alias l.="ls -d .[A-Za-z]* --color=auto"
# no spelling corrections on this commands
alias mv="nocorrect mv"
alias cp="nocorrect cp"
alias mkdir="nocorrect mkdir"
alias grep='nocorrect grep --color=auto'
alias dirs='dirs -v'
# eye candy!!!
alias d="ls --color"
alias ls="ls --color=auto"
alias la="ls --color=auto -al"
alias ll="ls --color -l"
# I'm the boss
alias rm="rm -if"
# speed kills! ;-)
alias ..="cd .."
alias ...="cd .. ; cd .."
alias l.="ls -d .[A-Za-z]* --color=auto"
# checksuming it
alias rsync='rsync -P --checksum'

# 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


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

### 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;
   ;;
   c3po*)
     export LANG=C;
     export LC_ALL=de_DE@euro;
   ;;

   *)
   ;;
esac

## HOST SPEZIFIC DATA
case $TERM in
  *xterm*|rxvt|(dt|k|E)term)
  # chpwd executes a command every time the directory changes
  # print is like echo, but with access to prompt expansion variables
  chpwd () {print -Pn "\e]0;%n@%m %d\a"}
  ;;
esac

zmodload -i zsh/complist

# display colored directory entries (e.g. for ls)
if [ -f ${HOME}/.dir_colors ]
then
    eval $(dircolors -b ${HOME}/.dir_colors)
elif [ -f /etc/DIR_COLORS ]
then
    eval $(dircolors -b /etc/DIR_COLORS)
fi

zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
zstyle ':completion:*:*:kill:*' list-colors '=%*=01;31'

# Load the completion system
autoload -U compinit
compinit


# display a _oversized_ menu for each completion (zsh is feels like the good old
# midnight commander ... )
#zstyle ':completion:*' menu select=1


#zstyle -e ':completion:*:ssh:*' hosts 'reply=($(sed -e "/^#/d" -e "s/ .*\$//" -e "s/,/ /g" /etc/ssh_known_hosts ~/.ssh/known_hosts ~/.ssh/known_hosts2 2>/dev/null))' 

# From the zshwiki. Hide CVS files/directores from being completed.
zstyle ':completion:*:(all-|)files' ignored-patterns '(|*/)CVS'
zstyle ':completion:*:cd:*' ignored-patterns '(*/)#CVS'

# Pull hosts from $HOME/.ssh/known_hosts, also from the wiki
#local _myhosts
#_myhosts=( ${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[0-9]*}%%\ *}%%,*} )

# frequently used hosts
_hosts=(`hostname`
        arath.foo.fh-furtwangen.de
        mia.foo.fh-furtwangen.de
        c3po.0xdef.net
        einstein.ai-lab.fh-furtwangen.de
        unfug.org
        jarjar.furcht.bar
        skywalker.furcht.bar
        palpatine.furcht.bar
        )

zstyle ':completion:*' hosts $_hosts

# frequently used users names
_users=(pfeifer hgndgtl unfug)
zstyle ':completion:*' users $_users

# turns on spelling correction for commands
setopt nocorrect
# ORRECTALL option turns on spelling correction for all arguments
setopt nocorrectall

# ignore duplicated entrys in history and with trailing spaces
setopt histignoredups
setopt histignorespace

# only exit or logout to leave zsh
#setopt ignoreeof

# let you type comment's
setopt interactivecomments

# autocd allow you to type a directory, without a cd prefix
#setopt autocd

# now you can negates pattern [ ls -d ^*.c ]
setopt extendedglob

setopt EXTENDEDGLOB     # file globbing is awesome
setopt AUTOMENU         # Tab-completion should cycle.
setopt AUTOLIST         # ... and list the possibilities.
setopt AUTO_PARAM_SLASH # Make directories pretty.
setopt ALWAYS_TO_END    # Push that cursor on completions.
setopt AUTOCD           # jump to the directory.
setopt HIST_VERIFY      # Make those history commands nice
setopt NO_BEEP          # self explanatory
setopt AUTO_NAME_DIRS   # change directories  to variable names
setopt CHASE_LINKS      # if you pwd from a symlink, you get the actual path


# prompt
if test -z $SSH_TTY
then
  PROMPT=$'%{\e[01;34m%}\%!,%l,%?,%{\e[01;33m%}\%1~ %{\e[01;32m%}$%{\e[0m%} '
  [ $UID = 0 ] && export PROMPT=$'%{\e[0;31m%}[%{\e[0m%}%n%{\e[0;31m%}@%{\e[0m%}%m%{\e[0;31m%}:%{\e[0m%}%~%{\e[0;31m%}]%{\e[0m%}%# '
else
  PROMPT=$'%{\e[01;34m%}\%!,%m,%?,%{\e[01;33m%}\%1~ %{\e[01;32m%}$%{\e[0m%} '
  [ $UID = 0 ] && export PROMPT=$'%{\e[0;31m%}[%{\e[0m%}%n%{\e[0;31m%}@%{\e[0m%}%m%{\e[0;31m%}:%{\e[0m%}%~%{\e[0;31m%}]%{\e[0m%}%# '
fi

# woo! so glad i found this. jump to each element in a path with m-f m-b, same
# for kill-word, etc.
export WORDCHARS=''
export DIRSTACKSIZE=30         # max push/pop stack

watch=(notme)
LOGCHECK=300
WATCHFMT='%n %a %l from %m at %t.'

# emacs keybinding's
bindkey -e

# insert all expansions for expand completer
zstyle ':completion:*:expand:*' tag-order all-expansions

# formatting and messages
zstyle ':completion:*' verbose yes
zstyle ':completion:*:descriptions' format '%B%d%b'
zstyle ':completion:*:messages' format '%d'
zstyle ':completion:*:warnings' format 'No matches for: %d'
zstyle ':completion:*:corrections' format '%B%d (errors: %e)%b'
zstyle ':completion:*' group-name ''


# of course
export EDITOR='/usr/bin/vim'

# favorite pager (give more information)
export PAGER='/usr/bin/less -M'

# work with history mechanism
HISTSIZE=1000
SAVEHIST=1000
HISTFILE=~/.zhistory


#############################################################################
# COMMANDLINE COMPLETITION SECTION

# only directories for cd && pushcd; nice feature!
# or "compctl -g '*(-/)' cd pushd" without hidden dirs
compctl -g '*(-/)' + -g '.*(-/)' -v cd pushd

# only java files for javac (see a
#compctl -g '*.java' javac

# for ssh && scp connection's
compctl -k hosts ssh scp


#############################################################################
# KEY - BINDINGS

# interactive help? type CTRL-x; CTRL-h
bindkey "^X^H" run-help
# search for command backward
bindkey "^r" history-incremental-search-backward
# emulate some bash feelings
#bindkey "" backward-delete-word

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

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

# next two entrys found on svens hp => guckes.net
# _P = make items "public"
function _P
{
    ( for i in $*; do
      if [[ -f $i ]] then; chmod 644 $i; fi
      if [[ -d $i ]] then; chmod 755 $i; fi
      done; )
}

# _p = make items "private"
function _p
{
    ( for i in $*; do
      if [[ -f $i ]] then; chmod 600 $i; fi
      if [[ -d $i ]] then; chmod 700 $i; fi
      done; )
}

alias calc="noglob _calc" calcfx="noglob _calcfx"
function _calc () {
             awk "BEGIN { print $* ; }"
}

function _calcfx () {
            gawk -v CONVFMT="%12.2f" -v OFMT="%.9g"  "BEGIN { print $* ; }"
}

function teetime ()
{
  # don't worry: visual bell == true! ;-)
  echo "sleep for $1"
  sleep $1;while true;do echo -ne '\a';sleep 0.1s;done
}



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