# ~/.zshrc
# -- David Faure

[ -f ~dfaure/txt/setup/perso.zsh ] && . ~dfaure/txt/setup/perso.zsh

#Machine-dependent stuff
[ -f ~/.zshrc_local ] && . ~/.zshrc_local

test -z "$d" && d=d

path=($path /d/other/inst/bin /usr/X11R6/bin)

# E.g. on elora, or cleo
[ -d /d/films/bin ] && path=($path /d/films/bin)

#test -f ~/.ssh-server && . ~/.ssh-server
#test -f ~/.gpg-server && . ~/.gpg-server
test -f ~/.dbus-server && . ~/.dbus-server

# necessary on kubuntu:
test -n "$HOSTNAME" || export HOSTNAME=`cat /etc/hostname`

#test -f ~/.keychain/$HOSTNAME-sh && source ~/.keychain/$HOSTNAME-sh
#test -f ~/.keychain/$HOSTNAME-sh-gpg && source ~/.keychain/$HOSTNAME-sh-gpg

# Completion for zsh, if you have a slow machine comment these lines !!!
#_compdir=/usr/share/zsh/functions/Core
#[[ -z $fpath[(r)$_compdir] ]] && fpath=($fpath $_compdir)
fpath=($fpath /d/kde/src/kdesdk/scripts/completions/zsh)
fpath=($HOME/src/zshkde-completions-0.1 $fpath)

autoload -U compinit
# compinit enables the huge completion catalogue in $fpath, says tronical
# David: added -C to avoid a warning when doing sudo -s ... removed again, the right solution is sudo -s -H.
compinit

alias su='sudo -s -H'
alias be='sudo -s -H -u' # example:  be david

export PATH=/d/kde/src/t/kdesdk/scripts:$PATH
export PATH=/d/kdab/src/kdab-utils/Scripts:$PATH:$HOME/bin:/sbin:/usr/sbin:/mnt/perso/bin:.
export KDESRC=/d/kde/src
export KDEBUILD=/d/kde/build

DBUSDIR=/d/kde/inst/dbusdir
export PKG_CONFIG_PATH=$DBUSDIR/lib/pkgconfig:$PKG_CONFIG_PATH
export PATH=$DBUSDIR/bin:$PATH
export LD_LIBRARY_PATH=$DBUSDIR/lib:$LD_LIBRARY_PATH

if test -d /d/other/inst/icecream/bin; then
  export PATH=/d/other/inst/icecream/bin:$PATH
else
  export PATH=/usr/lib/icecc/bin:$PATH
fi

export PKG_CONFIG_PATH=/d/other/inst/icecream/lib/pkgconfig:$PKG_CONFIG_PATH

export JAVA_HOME=/usr/jdk-sun1.2.2

# compctl
# Complétion multi-niveaux
#. ~/bin/multicomp.zsh
#compctl -D -f + -U -K multicomp

# Improve ssh and scp completion
logins=(`cat ~dfaure/txt/.logins`)
zstyle ':completion:*:my-accounts' users-hosts $logins

# talk write finger
#function TALKABLE { reply=(`users | sed s/$USER//g` cmaion@ifhamy acassen@whadim sdesitte@horwen.resF hsimonch@ifhamy fcarli@f-carli.tel tflorent@i502.resi naversen@i324 mscrizzi@bernie.resf kader@i212.resi pyv@i405.resi); }
#compctl -K TALKABLE talk write finger
# cd, pushd
compctl -g '*(-/)' + -g '.*(-/)' cd pushd
# gzip, ...
compctl -x 'R[-*[dt],^*]' -g '*.(gz|z|Z|t[agp]z|tarZ|tz)' + -g '*(-/)' + -f - \
        's[]' -g '^*(.(tz|gz|t[agp]z|tarZ|zip|ZIP|jpg|JPG|gif|GIF|[zZ])|[~#])' \
        + -f -- gzip
compctl -g '*.(gz|z|Z|t[agp]z|tarZ|tz)' + -g '*(-/)' gunzip gzcat zcat
# zip
compctl -g '*.(zip|Zip|ZIP)' + -g '*(-/)' unzip
# bzip2
compctl -g '*.([bB][zZ]2)' + -g '*(-/)' bunzip2
# xdvi kdvi
compctl -g '*.dvi' + -g '*(-/)' + -f xdvi kdvi
# Qt designer
compctl -g '*.ui' + -g '*(-/)' + -f designer
# make - MARCHE PAS
#compctl -s "\$(awk '/^[a-zA-Z0-9][^     ]+:/ {print \$1}' FS=: [mM]akefile)" -x\
#        'c[-1,-f]' -f -- make gmake pmake
# dd
compctl -k '(if of conv ibs obs bs cbs files skip file seek count)' \
        -S '=' -x 's[if=], s[of=]' -f - 'C[0,conv=*,*] n[-1,,], s[conv=]' \
        -k '(ascii ebcdic ibm block unblock lcase ucase swap noerror sync)' \
        -q -S ',' - 'n[-1,=]' -X '<number>'  -- dd
# tar
compctl -f -x 'W[1,*(z*f|f*z)*] p[2]' -g '*.(tar.gz|tgz|tar.Z|taz|ksp|kwd|kpr|kil)' + -g '*(-/)' - \
        'W[1,*f*] p[2]' -g '*.tar' + -g '*(-/)' -- gnutar gtar tar
# su
compctl -u -x 'w[1,-]p[3,-1]' -l sh - 'w[1,-]' -u - 'p[2,-1]' -l sh -- su
# gv kghostview
compctl -g '*.ps' + -g '*(-/)' + -f kghostview gv
# tex, latex, ...
compctl -g '*.tex*' + -g '*(-/)' {,la,gla,ams{la,},{g,}sli}tex texi2dvi
# rpm
#compctl -s '$(rpm -qa)' \
#        -x 's[--]' -s 'oldpackage percent replacefiles replacepkgs noscripts
#                       root excludedocs includedocs test upgrade test clean
#                       short-circuit sign recompile rebuild resign querytags
#                       queryformat version help quiet rcfile force hash' - \
#        's[ftp:]' -P '//' -s '$(</u/zsh/ftphosts)' -S '/' - \
#        'c[-1,--root]' -g '*(-/)' - \
#        'c[-1,--rcfile]' -f - \
#        'p[1] s[-b]' -k '(p l c i b a)' - \
#        'c[-1,--queryformat] N[-1,{]' \
#                -s '"${${(f)$(rpm --querytags)}#RPMTAG_}"' -S '}' - \
#        'W[1,-q*] C[-1,-([^-]*|)f*]' -f - \
#        'W[1,-i*], W[1,-q*] C[-1,-([^-]*|)p*]' \
#                -g '*.rpm' + -g '*(-/)' + -f -- rpm
#
# kspread
compctl -g '*.(ksp|ods)' + -g '*(-/)' kspread
# kword
compctl -g '*.(kwd|odt)' + -g '*(-/)' kword

# Commands
#   [[ -x /usr/bin/newmail ]] && /usr/bin/newmail

#bindkey -s "\e[17~" "rlogin ifhamy"
#bindkey -s "\e[29~" "ftp ifhamy"
#bindkey -s "\e[18~" "telnet ifhp703"
#bindkey -s "\e[31~" "ftp ifhp703"
#bindkey -s "\e[19~" "rlogin aurora"
#bindkey -s "\e[32~" "ftp aurora"

bindkey '^B' copy-prev-word

test -f /etc/DIR_COLORS && eval `dircolors /etc/DIR_COLORS`

alias xemacs="LANG=C xemacs" # see xem
alias gdbkword='gdb -nw $KOFFICEPREFIX/bin/kword'
alias lgdb='libtool --mode=execute gdb'
alias kworda4='kword --template $KOFFICEPREFIX/share/apps/kword/templates/Normal/A4.desktop'
alias rm='rm -i'
#alias hexdump='od -ctx1'
alias hexdump=xxd # saw dirk using it
# breaks completion alias diff='diff -ur -xCVS -xMakefile -xMakefile.in'
alias diff='diff -urp'
#alias calc='bc'
alias xs=cd
alias vi=vim
alias mutt='LANG="" LC_ALL="" mutt'
#alias cqt2='export QTDIR=$KDESRC/qt-copy; cd $QTDIR'
alias cqt3='cd $KDESRC/3/qt-copy'
alias cqt4='cd /d/qt/4/kde-qt-4.5'
#alias cqte='cd /d/qt/embedded'
alias cipc3='cd /d/kdab/src/IPC/Qt3'
alias cipc='cd /d/kdab/src/IPC/trunk'
alias wqt='echo $QTDIR'
#alias ckde='source $KDEDIRCVS/bin/kdedev && cd $KDESRC'
alias ckde='cd $KDESRC'
alias ckde3='cd $KDESRC/3'
alias ckde4='cd $KDESRC/4'
alias ckdelibstrunk='cd /d/kde/inst/kde4libstrunk'
alias ckoffice='cd $KDESRC/3/koffice'
#alias cfilters='ckoffice ; cd kspread/filters/csv'
alias capps='source $KDEDIRCVS/bin/kdedev && cd /d/kde/apps'
alias ckonq='cd t/kdebase/apps/konqueror/src'
alias cdolphin='cd t/kdebase/apps/dolphin/src'
#alias ckbb='ckde && cd kdesdk/kbugbuster'
alias ckdab='cd /d/kdab/src'
alias csevic='ckdab ; cd ERCO ; cd Sevic'
alias grpe=grep
alias rgrep="wcgrep -r"
## doesn't work, but -r --include is still nice.
#alias rgrepcmakelists="grep -r --include=CMakeLists.txt $* ."
alias mpg123="mpg321 -o alsa"
# as suggested by carsten
export GREP_OPTIONS="--directories=skip --exclude=*.svn-base"
# for the dump script
export KDABWWWNICK=dfaure

alias yo=yokadi
alias gdb=cgdb

alias make='makeobj'
alias ma='cs ; if test -f make.sh; then zsh make.sh ; else makeobj ; fi'

alias maek=make
alias mkae=make
alias mi='make install'
alias mci='( makeobj -j `~dfaure/txt/kde/scripts/build/jvalue` -k compile && cb && makeobj install )'
alias mie='makeobj install-exec'
alias um='unsermake '
alias svo=sshmail
alias gr=grep
alias commit='test -d CVS && ( cvs commit $* || true ) || ( test -d .svn && ( svn commit $* || true ) ) || echo "no CVS or SVN here"'
alias mf='nocorrect mf'
#alias svndi='svn diff > /tmp/svndiff; test -s /tmp/svndiff && vi /tmp/svndiff'
#alias xv=display
#alias cvs="if test -d .svn; then svn \"$*\"; else /usr/bin/cvs \"$*\"; fi"

# recode doesn't update mtime by default, which is quite stupid
alias recode="recode -t"

# ================ KDAB functions

# open plan for this month
function oothis () {
         svn up /d/kdab/src/Documents/Plan
         ooffice /d/kdab/src/Documents/Plan/`date +"%Y-%m"`/Team\ Minitel.ods
}

#open plan for next month
function oonext () {
         svn up /d/kdab/src/Documents/Plan
         if [ `date +%m` = 12 ]; then
            ooffice /d/kdab/src/Documents/Plan/$((`date +%Y`+1))-01/Team\ Minitel.ods
         else
            ooffice /d/kdab/src/Documents/Plan/`date +%Y`-$((`date +%m` +1))/Team\ Minitel.ods
         fi
}

# ================ env vars

export TEXINPUTS=":~/doc/LaTeX" 
export WANT_AUTOCONF_2_5=1
# Still needed, for freedesktop.org
export CVS_RSH=ssh

export CDPATH=.:$KDESRC

stty erase 

ulimit -c unlimited

#export CVSROOT=:ext:faure@cvs.kde.org:/home/kde
#export SVNURL=svn+ssh://dfaure@svn.kde.org/home/kde/
export KDESVN=svn+ssh://dfaure@svn.kde.org/home/kde/
export KDABSVN=svn+ssh://svn.kdab.net/home/SVN-klaralv
export KDABGIT=svn.kdab.net:/home/git
export SVNUSER=dfaure
export SVNPROTOCOL=svn+ssh
export SVNSERVER=svn.kde.org
#export PATH=$KDESRC/4/kdenonbeta/unsermake:$PATH
#export UNSERMAKE=$KDESRC/kdenonbeta/unsermake/unsermake
export UNSERMAKE_OPTS="--real-compare"
export QTEST_COLORED=1

#if [ $TERM = ansi ]; then
   #export TERM=vt100
#fi

# DIR_COLORS is better
#LS_COLORS='no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.deb=01;31:*.jpg=01;35:*.gif=01;35:*.bmp=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.mpg=01;37:*.avi=01;37:*.gl=01;37:*.dl=01;37:';
#export LS_COLORS 

export OBJ_REPLACEMENT='s#/kde/src/#/kde/build/#'
unset OBJ_SUBDIR
alias cb='cd /kde/src /kde/build'
alias cs='cd /kde/build /kde/src'


export VALGRIND_OPTS="--num-callers=50 --suppressions=/d/kde/src/t/kdesdk/scripts/kde.supp"
#alias cachegrind="valgrind --tool=cachegrind"
#alias addrcheck="valgrind --tool=addrcheck"
alias memcheck="valgrind --tool=memcheck"
alias addrcheck=memcheck
alias leakcheck="valgrind --tool=memcheck --leak-check=yes"
alias massif="valgrind --tool=massif --alloc-fn='qMalloc(unsigned long)'"
   #then use ms_print to read the output
# and use callgrind for profiling.
# optionally with --instr-atstart=no / callgrind_control -i on
alias callgrind="valgrind --tool=callgrind"

export KDE_DEBUG=1
# export MALLOC_CHECK_ to disable glibc's malloc check, since it prevents getting drkonqi
#export MALLOC_CHECK_=0
source ~dfaure/txt/.kdexecutor
[ -d /d/kdab/src/kdab-utils ] && source /d/kdab/src/kdab-utils/zsh-functions/svn-glimpse-extension
export KDABCLIPBOARD=5601

#export MAKE="make -j 2"
#export INSTALL="/usr/bin/install -p"
#export CXXFLAGS="-fomit-frame-pointer -pipe -mcpu=pentium -march=pentium \
# -fno-rtti -fno-check-new -Wall -pedantic -W -Wpointer-arith \
# -Wmissing-prototypes -Wwrite-strings -Wno-long-long -fno-builtin"
# -Woverloaded-virtual

function warnwhendone { eval $@; kdialog --passivepopup "command finished $@" }

#function dmalloc { eval `command dmalloc -b $*`; }
if type -p findup >/dev/null; then
 #function cd() {
  #builtin cd $1 $2
  #_f=`findup .df-setup`
  #test -z "$_f" && _f=`findup .kdab-setup`
  #if test -n "$_f" -a "$_lastf" != "$_f"; then
    #echo "Loading $_f"
    #_lastf="$_f"
    #source "$_f"
  #fi
 #}
 #
 function cd() {
  local _f1 _f2 _f1d _f2d _f _d _pwd
  builtin cd $*
  _f1=`findup .df-setup`
  _f2=`findup .kdab-setup`
  if test -n "$_f1"; then
    _f1d=`dirname $_f1`
  fi
  if test -n "$_f2"; then
    _f2d=`dirname $_f2`
  fi

  if test ${#_f1d} -ge ${#_f2d}; then
     _f=$_f1
     _d=$_f1d
  else
     _f=$_f2
     _d=$_f2d
  fi
  

  if test -n "$_f" -a "$_lastf" != "$_f"; then
    _pwd="$PWD"
    builtin cd "$_d"
    echo "Loading $_f"
    source "$_f"
    builtin cd "$_pwd"
    _lastf="$_f"
  fi
}

fi

export KDTOOLSDIR=/d/kdab/src/kdtools

#source $KDEDIRCVS/bin/kdedev
#test -f ~/.kde/env/kdedirs.sh && source ~/.kde/env/kdedirs.sh

# Machine-dependent stuff
[ -f ~/.zshrc_local_2 ] && . ~/.zshrc_local_2

# Startup directory .df-setup
cd .

. /etc/profile.d/autojump.zsh

