323635004dc6468d7e42fbfcfa833b5ba5e365f6
[grml-etc-core.git] / etc / skel / .zshrc
1 # Filename:      .zshrc
2 # Purpose:       config file for zsh
3 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
4 # Bug-Reports:   see http://grml.org/bugs/
5 # License:       This file is licensed under the GPL v2.
6 # Latest change: Don Okt 26 00:50:18 CEST 2006 [mika]
7 ################################################################################
8
9 # source ~/.zshrc.global {{{
10 # see /etc/zsh/zshrc for some general settings
11 # If you don't have write permissions to /etc/zsh/zshrc on your own
12 # copy the file to your $HOME as /.zshrc.global and we source it:
13   if [ -r ~/.zshrc.global ] ; then
14      . ~/.zshrc.global
15   fi
16 # }}}
17
18 # completion system {{{
19 # just make sure it is loaded in this file too
20   type compinit &>/dev/null || { autoload -U compinit && compinit }
21 # }}}
22
23 ## variables {{{
24
25 # set terminal property (used e.g. by msgid-chooser)
26   export COLORTERM="yes"
27
28 # set default browser
29   if [ -z $BROWSER ] ; then
30      if [ -n "$DISPLAY" ] ; then
31         [ -x =firefox ] && export BROWSER=firefox
32      else
33         [ -x =w3m ] && export BROWSER=w3m
34      fi
35   fi
36   (( ${+PAGER} ))   || export PAGER="less"
37
38 # export qtdir
39   [ -d /usr/share/qt3 ] && export QTDIR=/usr/share/qt3
40   [ -d /usr/share/qt4 ] && export QTDIR=/usr/share/qt4
41
42 # support running 'jikes *.java && jamvm HelloWorld' OOTB:
43   [ -f /usr/share/classpath/glibj.zip ] && export JIKESPATH=/usr/share/classpath/glibj.zip
44 # }}}
45
46 ## set options {{{
47
48 # Allow comments even in interactive shells i. e.
49 # $ uname # This command prints system informations
50 # zsh: bad pattern: #
51 # $ setopt interactivecomments
52 # $ uname # This command prints system informations
53 # Linux
54 #  setopt interactivecomments
55
56 # ctrl-s will no longer freeze the terminal.
57 #  stty erase "^?"
58
59 # }}}
60
61 # {{{ global aliases
62 # These do not have to be at the beginning of the command line.
63 # Avoid typing cd ../../ for going two dirs down and so on
64 # Usage, e.g.: "$ cd ...' or just '$ ...' with 'setopt auto_cd'
65   alias -g '...'='../..'
66   alias -g '....'='../../..'
67 # Usage is "$ somecommand C (this pipes it into 'wc -l'):
68   alias -g BG='& exit'
69   alias -g C='|wc -l'
70   alias -g G='|grep'
71   alias -g H='|head'
72   alias -g Hl=' --help |& less -r'
73   alias -g K='|keep'
74   alias -g L='|less'
75   alias -g LL='|& less -r'
76   alias -g M='|most'
77   alias -g N='&>/dev/null'
78   alias -g R='| tr A-z N-za-m'
79   alias -g SL='| sort | less'
80   alias -g S='| sort'
81   alias -g T='|tail'
82   alias -g V='| vim -'
83 # }}}
84
85 ## another approach for global aliases: cloning vim's abbreviation feature {{{
86 # http://zshwiki.org/home/examples/zleiab
87 # typeset -A abbreviations
88 # abbreviations=(
89 #   "Im"    "| more"
90 #   "Ia"    "| awk"
91 #   "Ig"    "| grep"
92 #   "Ieg"   "| egrep"
93 #   "Iag"   "| agrep"
94 #   "Igr"   "| groff -s -p -t -e -Tlatin1 -mandoc"
95 #   "Ip"    "| $PAGER"
96 #   "Ih"    "| head"
97 #   "Ik"    "| keep"
98 #   "It"    "| tail"
99 #   "Is"    "| sort"
100 #   "Iv"    "| ${VISUAL:-${EDITOR}}"
101 #   "Iw"    "| wc"
102 #   "Ix"    "| xargs"
103 # )
104
105 # magic-abbrev-expand() {
106 #     local MATCH
107 #     LBUFFER=${LBUFFER%%(#m)[_a-zA-Z0-9]#}
108 #     LBUFFER+=${abbreviations[$MATCH]:-$MATCH}
109 #     zle self-insert
110 # }
111
112 # no-magic-abbrev-expand() {
113 #   LBUFFER+=' '
114 # }
115
116 # zle -N magic-abbrev-expand
117 # zle -N no-magic-abbrev-expand
118 # bindkey " " magic-abbrev-expand
119 # bindkey "^x " no-magic-abbrev-expand
120 # }}}
121
122 ## aliases {{{
123
124 # Xterm resizing-fu.
125 # Based on http://svn.kitenet.net/trunk/home-full/.zshrc?rev=11710&view=log (by Joey Hess)
126   alias hide='echo -en "\033]50;nil2\007"'
127   alias tiny='echo -en "\033]50;-misc-fixed-medium-r-normal-*-*-80-*-*-c-*-iso8859-15\007"'
128   alias small='echo -en "\033]50;6x10\007"'
129   alias medium='echo -en "\033]50;-misc-fixed-medium-r-normal--13-120-75-75-c-80-iso8859-15\007"'
130   alias default='echo -e "\033]50;-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-15\007"'
131   alias large='echo -en "\033]50;-misc-fixed-medium-r-normal-*-*-150-*-*-c-*-iso8859-15\007"'
132   alias huge='echo -en "\033]50;-misc-fixed-medium-r-normal-*-*-210-*-*-c-*-iso8859-15\007"'
133   alias smartfont='echo -en "\033]50;-artwiz-smoothansi-*-*-*-*-*-*-*-*-*-*-*-*\007"'
134   alias semifont='echo -en "\033]50;-misc-fixed-medium-r-semicondensed-*-*-120-*-*-*-*-iso8859-15\007"'
135 #  if [ "$TERM" = "xterm" ] && [ "$LINES" -ge 50 ] && [ "$COLUMNS" -ge 100 ] && [ -z "$SSH_CONNECTION" ]; then
136 #          large
137 #  fi
138
139 # general
140   alias da='du -sch'
141   alias j='jobs -l'
142 #  alias u='translate -i'          # translate
143
144 # compile stuff
145   alias CO="./configure"
146   alias CH="./configure --help"
147
148 # http://conkeror.mozdev.org/
149   alias conkeror='firefox -chrome chrome://conkeror/content'
150
151 # arch/tla stuff
152   alias ldiff='tla what-changed --diffs | less'
153   alias tbp='tla-buildpackage'
154   alias mirror='tla archive-mirror'
155   alias commit='tla commit'
156   alias merge='tla star-merge'
157
158 # listing stuff
159   alias dir="ls -lSrah"
160   alias lad='ls -d .*(/)'                # only show dot-directories
161   alias lsa='ls -a .*(.)'                # only show dot-files
162   alias lss='ls -l *(s,S,t)'             # only files with setgid/setuid/sticky flag
163   alias lsl='ls -l *(@[1,10])'           # only symlinks
164   alias lsx='ls -l *(*[1,10])'           # only executables
165   alias lsw='ls -ld *(R,W,X.^ND/)'       # world-{readable,writable,executable} files
166   alias lsbig="ls -flh *(.OL[1,10])"     # display the biggest files
167   alias lsd='ls -d *(/)'                 # only show directories
168   alias lse='ls -d *(/^F)'               # only show empty directories
169   alias lsnew="ls -rl *(D.om[1,10])"     # display the newest files
170   alias lsold="ls -rtlh *(D.om[1,10])"   # display the oldest files
171   alias lssmall="ls -Srl *(.oL[1,10])"   # display the smallest files
172
173 # chmod
174   alias rw-='chmod 600'
175   alias rwx='chmod 700'
176   alias r--='chmod 644'
177   alias r-x='chmod 755'
178
179 # some useful aliases
180   alias md='mkdir -p'
181
182 # console stuff
183   alias cmplayer='mplayer -vo fbdev'
184 #  alias fbmplayer='mplayer -vo fbdev'
185   alias fbmplayer='mplayer -vo fbdev -fs -zoom'
186   alias fblinks='links2 -driver fb'
187
188 # ignore ~/.ssh/known_hosts entries
189 #  alias insecssh='ssh -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=/dev/null" -o "PreferredAuthentications=keyboard-interactive"'
190   alias insecssh='ssh -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=/dev/null"'
191
192 # use colors when browsing man pages (if not using pinfo or PAGER=most)
193   [ -d ~/.terminfo/ ] && alias man='TERMINFO=~/.terminfo/ LESS=C TERM=mostlike PAGER=less man'
194
195 # check whether Debian's package management (dpkg) is running
196   alias check_dpkg_running="$SUDO dpkg_running"
197 # }}}
198
199 ## useful functions {{{
200
201 # functions without detailed explanation:
202   agoogle() { ${=BROWSER} "http://groups.google.com/groups?as_uauthors=$*" ; }
203   bk()      { cp -b ${1} ${1}_`date --iso-8601=m` }
204   cdiff()   { diff -crd "$*" | egrep -v "^Only in |^Binary files " }
205   cl()      { cd $1 && ls -a }        # cd && ls
206   cvsa()    { cvs add $* && cvs com -m 'initial checkin' $* }
207   cvsd()    { cvs diff -N $* |& $PAGER }
208   cvsl()    { cvs log $* |& $PAGER }
209   cvsq()    { cvs -nq update }
210   cvsr()    { rcs2log $* | $PAGER }
211   cvss()    { cvs status -v $* }
212   debbug()  { ${=BROWSER} "http://bugs.debian.org/$*" }
213   debbugm() { bts show --mbox $1 } # provide bugnummer as $1
214   disassemble(){ gcc -pipe -S -o - -O -g $* | as -aldh -o /dev/null }
215   dmoz()    { ${=BROWSER} http://search.dmoz.org/cgi-bin/search\?search=${1// /_} }
216   dwicti()  { ${=BROWSER} http://de.wiktionary.org/wiki/${(C)1// /_} }
217   ewicti()  { ${=BROWSER} http://en.wiktionary.org/wiki/${(C)1// /_} }
218   fir()     { firefox -a firefox -remote "openURL($1)" }
219   ggogle()  { ${=BROWSER} "http://groups.google.com/groups?q=$*" }
220   google()  { ${=BROWSER} "http://www.google.com/search?&num=100&q=$*" }
221   mdiff()   { diff -udrP "$1" "$2" > diff.`date "+%Y-%m-%d"`."$1" }
222   memusage(){ ps aux | awk '{if (NR > 1) print $5; if (NR > 2) print "+"} END { print "p" }' | dc }
223   mggogle() { ${=BROWSER} "http://groups.google.com/groups?selm=$*" }
224   netcraft(){ ${=BROWSER} "http://toolbar.netcraft.com/site_report?url=$1" }
225   oleo()    { ${=BROWSER} "http://dict.leo.org/?search=$*" }
226   shtar()   { gunzip -c $1 | tar -tf - -- | $PAGER }
227   shtgz()   { tar -ztf $1 | $PAGER }
228   shzip()   { unzip -l $1 | $PAGER }
229   sig()     { agrep -d '^-- $' "$*" ~/.Signature }
230   swiki()   { ${=BROWSER} http://de.wikipedia.org/wiki/Spezial:Search/${(C)1} }
231   udiff()   { diff -urd $* | egrep -v "^Only in |^Binary files " }
232   viless()  { vim --cmd 'let no_plugin_maps = 1' -c "so \$VIMRUNTIME/macros/less.vim" "${@:--}" }
233   wikide () { ${=BROWSER} http://de.wikipedia.org/wiki/"${(C)*}" }
234   wikien()  { ${=BROWSER} http://en.wikipedia.org/wiki/"$*" }
235   wodeb ()  { ${=BROWSER} "http://packages.debian.org/cgi-bin/search_contents.pl?word=$1&version=${2:-unstable}" }
236
237   which google >/dev/null 2>&1 && gex () { google "\"[ $1]\" $*" } # exact search at google
238
239 # Function Usage: doc packagename
240   doc() { cd /usr/share/doc/$1 && ls }
241   _doc() { _files -W /usr/share/doc -/ }
242   compdef _doc doc
243
244 # debian upgrade
245   upgrade () {
246     if [ -z $1 ] ; then
247         $SUDO apt-get update
248         $SUDO apt-get -u upgrade
249     else
250         ssh $1 $SUDO apt-get update
251         # ask before the upgrade
252         local dummy
253         ssh $1 $SUDO apt-get --no-act upgrade
254         echo -n "Process the upgrade ?"
255         read -q dummy
256         if [[ $dummy == "y" ]] ; then
257             ssh $1 $SUDO apt-get -u upgrade --yes
258         fi
259     fi
260   }
261
262 # make screenshot of current desktop (use 'import' from ImageMagic)
263   sshot() {
264         [[ ! -d ~/shots  ]] && mkdir ~/shots
265         #cd ~/shots ; sleep 5 ; import -window root -depth 8 -quality 80 `date "+%Y-%m-%d--%H:%M:%S"`.png
266         cd ~/shots ; sleep 5; import -window root shot_`date --iso-8601=m`.jpg
267   }
268
269
270 # list images only
271   limg() {
272     local -a images
273     images=( *.{jpg,gif,png}(.N) )
274     if [[ $#images -eq 0 ]] ; then
275       print "No image files found"
276     else
277       ls "$@" "$images[@]"
278     fi
279   }
280
281
282 # create pdf file from source code
283   makereadable() {
284      output=$1
285      shift
286      a2ps --medium A4dj -E -o $output $*
287      ps2pdf $output
288   }
289
290 # zsh with perl-regex - use it e.g. via:
291 # regcheck '\s\d\.\d{3}\.\d{3} Euro' ' 1.000.000 Euro'
292   regcheck() {
293     zmodload -i zsh/pcre
294     pcre_compile $1 && \
295     pcre_match $2 && echo "regex matches" || echo "regex does not match"
296   }
297 # list files which have been modified within the last x days
298   new() { print -l *(m-$1) }
299
300 # grep the history
301   greph () { history 0 | grep $1 }
302   (grep --help 2>/dev/null |grep -- --color) >/dev/null && \
303     alias grep='grep --color=auto' # use colors when GNU grep with color-support
304   alias GREP='grep -i --color=auto'
305
306 # one blank line between each line
307   if [ -r ~/.terminfo/m/mostlike ] ; then
308 #     alias man2='MANPAGER="sed -e G |less" TERMINFO=~/.terminfo TERM=mostlike /usr/bin/man'
309      man2() { PAGER='dash -c "sed G | /usr/bin/less"' TERM=mostlike /usr/bin/man "$@" ; }
310   fi
311
312 # jump between directories
313 # Copyright 2005 Nikolai Weibull <nikolai@bitwi.se>
314 # notice: option AUTO_PUSHD has to be set
315   d(){
316     emulate -L zsh
317     autoload -U colors
318     local color=$fg_bold[blue]
319     integer i=0
320     dirs -p | while read dir; do
321       local num="${$(printf "%-4d " $i)/ /.}"
322       printf " %s  $color%s$reset_color\n" $num $dir
323       (( i++ ))
324     done
325     integer dir=-1
326     read -r 'dir?Jump to directory: ' || return
327     (( dir == -1 )) && return
328     if (( dir < 0 || dir >= i )); then
329       echo d: no such directory stack entry: $dir
330       return 1
331     fi
332     cd ~$dir
333   }
334
335 # provide useful information on globbing
336   H-Glob() {
337   echo -e "
338       /      directories
339       .      plain files
340       @      symbolic links
341       =      sockets
342       p      named pipes (FIFOs)
343       *      executable plain files (0100)
344       %      device files (character or block special)
345       %b     block special files
346       %c     character special files
347       r      owner-readable files (0400)
348       w      owner-writable files (0200)
349       x      owner-executable files (0100)
350       A      group-readable files (0040)
351       I      group-writable files (0020)
352       E      group-executable files (0010)
353       R      world-readable files (0004)
354       W      world-writable files (0002)
355       X      world-executable files (0001)
356       s      setuid files (04000)
357       S      setgid files (02000)
358       t      files with the sticky bit (01000)
359    print *(m-1)          # Dateien, die vor bis zu einem Tag modifiziert wurden.
360    print *(a1)           # Dateien, auf die vor einem Tag zugegriffen wurde.
361    print *(@)            # Nur Links
362    print *(Lk+50)        # Dateien die ueber 50 Kilobytes grosz sind
363    print *(Lk-50)        # Dateien die kleiner als 50 Kilobytes sind
364    print **/*.c          # Alle *.c - Dateien unterhalb von \$PWD
365    print **/*.c~file.c   # Alle *.c - Dateien, aber nicht 'file.c'
366    print (foo|bar).*     # Alle Dateien mit 'foo' und / oder 'bar' am Anfang
367    print *~*.*           # Nur Dateien ohne '.' in Namen
368    chmod 644 *(.^x)      # make all non-executable files publically readable
369    print -l *(.c|.h)     # Nur Dateien mit dem Suffix '.c' und / oder '.h'
370    print **/*(g:users:)  # Alle Dateien/Verzeichnisse der Gruppe >users<
371    echo /proc/*/cwd(:h:t:s/self//) # Analog zu >ps ax | awk '{print $1}'<"
372   }
373
374   lcheck() {
375    nm -go /usr/lib/lib*.a 2>/dev/null | grep ":[[:xdigit:]]\{8\} . .*$1"":[[:xdigit:]]\{8\} . .*$1"
376   }
377
378 # clean up directory
379   purge() {
380         FILES=(*~(N) .*~(N) \#*\#(N) *.o(N) a.out(N) *.core(N) *.cmo(N) *.cmi(N) .*.swp(N))
381         NBFILES=${#FILES}
382         if [[ $NBFILES > 0 ]]; then
383                 print $FILES
384                 local ans
385                 echo -n "Remove these files? [y/n] "
386                 read -q ans
387                 if [[ $ans == "y" ]]
388                 then
389                         rm ${FILES}
390                         echo ">> $PWD purged, $NBFILES files removed"
391                 else
392                         echo "Ok. .. than not.."
393                 fi
394         fi
395    }
396
397 # Translate DE<=>EN
398 # 'translate' looks up fot a word in a file with language-to-language
399 # translations (field separator should be " : "). A typical wordlist looks
400 # like at follows:
401 #  | english-word : german-transmission
402 # It's also only possible to translate english to german but not reciprocal.
403 # Use the following oneliner to turn back the sort order:
404 #  $ awk -F ':' '{ print $2" : "$1" "$3 }' \
405 #    /usr/local/lib/words/en-de.ISO-8859-1.vok > ~/.translate/de-en.ISO-8859-1.vok
406   trans() {
407         case "$1" in
408                 -[dD]*) translate -l de-en $2
409                 ;;
410                 -[eE]*) translate -l en-de $2
411                 ;;
412                 *)
413                 echo "Usage: $0 { -D | -E }"
414                 echo "         -D == German to English"
415                 echo "         -E == English to German"
416         esac
417   }
418
419 # Some quick Perl-hacks aka /useful/ oneliner
420 #  bew() { perl -le 'print unpack "B*","'$1'"' }
421 #  web() { perl -le 'print pack "B*","'$1'"' }
422 #  hew() { perl -le 'print unpack "H*","'$1'"' }
423 #  weh() { perl -le 'print pack "H*","'$1'"' }
424 #  pversion()    { perl -M$1 -le "print $1->VERSION" } # i. e."pversion LWP -> 5.79"
425 #  getlinks ()   { perl -ne 'while ( m/"((www|ftp|http):\/\/.*?)"/gc ) { print $1, "\n"; }' $* }
426 #  gethrefs ()   { perl -ne 'while ( m/href="([^"]*)"/gc ) { print $1, "\n"; }' $* }
427 #  getanames ()  { perl -ne 'while ( m/a name="([^"]*)"/gc ) { print $1, "\n"; }' $* }
428 #  getforms ()   { perl -ne 'while ( m:(\</?(input|form|select|option).*?\>):gic ) { print $1, "\n"; }' $* }
429 #  getstrings () { perl -ne 'while ( m/"(.*?)"/gc ) { print $1, "\n"; }' $*}
430 #  getanchors () { perl -ne 'while ( m/«([^«»\n]+)»/gc ) { print $1, "\n"; }' $* }
431 #  showINC ()    { perl -e 'for (@INC) { printf "%d %s\n", $i++, $_ }' }
432 #  vimpm ()      { vim `perldoc -l $1 | sed -e 's/pod$/pm/'` }
433 #  vimhelp ()    { vim -c "help $1" -c on -c "au! VimEnter *" }
434
435 # plap foo -- list all occurrences of program in the current PATH
436   plap() {
437         if [[ $# = 0 ]]
438         then
439                 echo "Usage:    $0 program"
440                 echo "Example:  $0 zsh"
441                 echo "Lists all occurrences of program in the current PATH."
442         else
443                 ls -l ${^path}/*$1*(*N)
444         fi
445   }
446
447 # Found in the mailinglistarchive from Zsh (IIRC ~1996)
448   selhist() {
449         emulate -L zsh
450         local TAB=$'\t';
451         (( $# < 1 )) && {
452                 echo "Usage: $0 command"
453                 return 1
454         };
455         cmd=(${(f)"$(grep -w $1 $HISTFILE | sort | uniq | pr -tn)"})
456         print -l $cmd | less -F
457         echo -n "enter number of desired command [1 - $(( ${#cmd[@]} - 1 ))]: "
458         local answer
459         read answer
460         print -z "${cmd[$answer]#*$TAB}"
461   }
462
463 # mkdir && cd
464   mcd() { mkdir -p "$@"; cd "$@" }  # mkdir && cd
465
466 # cd && ls
467   cl() { cd $1 && ls -a }
468
469 # Use vim to convert plaintext to HTML
470   2html() { vim -u NONE -n -c ':syntax on' -c ':so $VIMRUNTIME/syntax/2html.vim' -c ':wqa' $1 > /dev/null 2> /dev/null }
471
472 # Usage: simple-extract <file>
473 # Description: extracts archived files (maybe)
474   simple-extract () {
475         if [[ -f $1 ]]
476         then
477                 case $1 in
478                         *.tar.bz2)  bzip2 -v -d $1      ;;
479                         *.tar.gz)   tar -xvzf $1        ;;
480                         *.rar)      unrar $1            ;;
481                         *.deb)      ar -x $1            ;;
482                         *.bz2)      bzip2 -d $1         ;;
483                         *.lzh)      lha x $1            ;;
484                         *.gz)       gunzip -d $1        ;;
485                         *.tar)      tar -xvf $1         ;;
486                         *.tgz)      gunzip -d $1        ;;
487                         *.tbz2)     tar -jxvf $1        ;;
488                         *.zip)      unzip $1            ;;
489                         *.Z)        uncompress $1       ;;
490                         *)          echo "'$1' Error. Please go away" ;;
491                 esac
492         else
493                 echo "'$1' is not a valid file"
494         fi
495   }
496
497 # Usage: smartcompress <file> (<type>)
498 # Description: compresses files or a directory.  Defaults to tar.gz
499   smartcompress() {
500         if [ $2 ]; then
501                 case $2 in
502                         tgz | tar.gz)   tar -zcvf$1.$2 $1 ;;
503                         tbz2 | tar.bz2) tar -jcvf$1.$2 $1 ;;
504                         tar.Z)          tar -Zcvf$1.$2 $1 ;;
505                         tar)            tar -cvf$1.$2  $1 ;;
506                         gz | gzip)      gzip           $1 ;;
507                         bz2 | bzip2)    bzip2          $1 ;;
508                         *)
509                         echo "Error: $2 is not a valid compression type"
510                         ;;
511                 esac
512         else
513                 smartcompress $1 tar.gz
514         fi
515   }
516
517 # Usage: show-archive <archive>
518 # Description: view archive without unpack
519   show-archive() {
520         if [[ -f $1 ]]
521         then
522                 case $1 in
523                         *.tar.gz)      gunzip -c $1 | tar -tf - -- ;;
524                         *.tar)         tar -tf $1 ;;
525                         *.tgz)         tar -ztf $1 ;;
526                         *.zip)         unzip -l $1 ;;
527                         *.bz2)         bzless $1 ;;
528                         *)             echo "'$1' Error. Please go away" ;;
529                 esac
530         else
531                 echo "'$1' is not a valid archive"
532         fi
533   }
534
535   folsym() {
536     if [[ -e $1 || -h $1 ]]; then
537         file=$1
538     else
539         file=`which $1`
540     fi
541     if [[ -e $file || -L $file ]]; then
542         if [[ -L $file ]]; then
543             echo `ls -ld $file | perl -ane 'print $F[7]'` '->'
544             folsym `perl -le '$file = $ARGV[0];
545                               $dest = readlink $file;
546                               if ($dest !~ m{^/}) {
547                                   $file =~ s{(/?)[^/]*$}{$1$dest};
548                               } else {
549                                   $file = $dest;
550                               }
551                               $file =~ s{/{2,}}{/}g;
552                               while ($file =~ s{[^/]+/\.\./}{}) {
553                                   ;
554                               }
555                               $file =~ s{^(/\.\.)+}{};
556                               print $file' $file`
557         else
558             ls -d $file
559         fi
560     else
561         echo $file
562     fi
563   }
564
565 # Use 'view' to read manpages, if u want colors, regex - search, ...
566 # like vi(m).
567 # It's shameless stolen from <http://www.vim.org/tips/tip.php?tip_id=167>
568   vman() { man $* | col -b | view -c 'set ft=man nomod nolist' - }
569
570 # search for various types or README file in dir and display them in $PAGER
571 # function readme() { $PAGER -- (#ia3)readme* }
572   readme() {
573         local files
574         files=(./(#i)*(read*me|lue*m(in|)ut)*(ND))
575         if (($#files))
576         then $PAGER $files
577         else
578                 print 'No README files.'
579         fi
580   }
581
582 # find all suid files in $PATH
583 # suidfind() { ls -latg $path | grep '^...s' }
584   suidfind() { ls -latg $path/*(sN) }
585
586 # See above but this is /better/ ... anywise ..
587   findsuid() {
588     print 'Output will be written to ~/suid_* ...'
589     $SUDO find / -type f \( -perm -4000 -o -perm -2000 \) -ls > ~/suid_suidfiles.`date "+%Y-%m-%d"`.out 2>&1
590     $SUDO find / -type d \( -perm -4000 -o -perm -2000 \) -ls > ~/suid_suiddirs.`date "+%Y-%m-%d"`.out 2>&1
591     $SUDO find / -type f \( -perm -2 -o -perm -20 \) -ls > ~/suid_writefiles.`date "+%Y-%m-%d"`.out 2>&1
592     $SUDO find / -type d \( -perm -2 -o -perm -20 \) -ls > ~/suid_writedirs.`date "+%Y-%m-%d"`.out 2>&1
593     print 'Finished'
594   }
595
596 # Reload functions.
597   refunc() {
598         for func in $argv
599         do
600                 unfunction $func
601                 autoload $func
602         done
603   }
604
605 # a small check to see which DIR is located on which server/partition.
606 # stolen and modified from Sven's zshrc.forall
607   dirspace() {
608         for dir in $path;
609         do
610                 (cd $dir; echo "-<$dir>"; du -shx .; echo);
611         done
612   }
613
614 # $ show_print `cat /etc/passwd`
615   slow_print() {
616         for argument in "${@}"
617         do
618                 for ((i = 1; i <= ${#1} ;i++)) {
619                         print -n "${argument[i]}"
620                         sleep 0.08
621                 }
622                 print -n " "
623         done
624         print ""
625   }
626
627   status() {
628         print ""
629         print "Date..: "$(date "+%Y-%m-%d %H:%M:%S")""
630         print "Shell.: Zsh $ZSH_VERSION (PID = $$, $SHLVL nests)"
631         print "Term..: $TTY ($TERM), $BAUD bauds, $COLUMNS x $LINES cars"
632         print "Login.: $LOGNAME (UID = $EUID) on $HOST"
633         print "System: $(cat /etc/[A-Za-z]*[_-][rv]e[lr]*)"
634         print "Uptime:$(uptime)"
635         print ""
636   }
637
638   audiorip() {
639         mkdir -p ~/ripps
640         cd ~/ripps
641         cdrdao read-cd --device $DEVICE --driver generic-mmc audiocd.toc
642         cdrdao read-cddb --device $DEVICE --driver generic-mmc audiocd.toc
643         echo " * Would you like to burn the cd now? (yes/no)"
644         read input
645         if
646                 [ "$input" = "yes" ]; then
647                 echo " ! Burning Audio CD"
648                 audioburn
649                 echo " * done."
650         else
651                 echo " ! Invalid response."
652         fi
653   }
654
655   audioburn() {
656         cd ~/ripps
657         cdrdao write --device $DEVICE --driver generic-mmc audiocd.toc
658         echo " * Should I remove the temporary files? (yes/no)"
659         read input
660         if [ "$input" = "yes" ]; then
661                 echo " ! Removing Temporary Files."
662                 cd ~
663                 rm -rf ~/ripps
664                 echo " * done."
665         else
666                 echo " ! Invalid response."
667         fi
668   }
669
670   mkaudiocd() {
671         cd ~/ripps
672         for i in *.[Mm][Pp]3; do mv "$i" `echo $i | tr '[A-Z]' '[a-z]'`; done
673         for i in *.mp3; do mv "$i" `echo $i | tr ' ' '_'`; done
674         for i in *.mp3; do mpg123 -w `basename $i .mp3`.wav $i; done
675         normalize -m *.wav
676         for i in *.wav; do sox $i.wav -r 44100 $i.wav resample; done
677   }
678
679   mkiso() {
680         echo " * Volume name "
681         read volume
682         echo " * ISO Name (ie. tmp.iso)"
683         read iso
684         echo " * Directory or File"
685         read files
686         mkisofs -o ~/$iso -A $volume -allow-multidot -J -R -iso-level 3 -V $volume -R $files
687   }
688
689 # generate thumbnails ;)
690   genthumbs () {
691     rm -rf thumb-* index.html
692     echo "
693 <html>
694   <head>
695     <title>Images</title>
696   </head>
697   <body>" > index.html
698     for f in *.(gif|jpeg|jpg|png)
699     do
700         convert -size 100x200 "$f" -resize 100x200 thumb-"$f"
701         echo "    <a href=\"$f\"><img src=\"thumb-$f\"></a>" >> index.html
702     done
703     echo "
704   </body>
705 </html>" >> index.html
706   }
707
708 # unset all limits (see zshbuiltins(1) /ulimit for details)
709   allulimit() {
710     ulimit -c unlimited
711     ulimit -d unlimited
712     ulimit -f unlimited
713     ulimit -l unlimited
714     ulimit -n unlimited
715     ulimit -s unlimited
716     ulimit -t unlimited
717   }
718
719 # ogg2mp3 with bitrate of 192
720   ogg2mp3_192() {
721     oggdec -o - ${1} | lame -b 192 - ${1:r}.mp3
722   }
723
724 # RFC 2396 URL encoding in Z-Shell
725   urlencode() {
726    setopt localoptions extendedglob
727    input=( ${(s::)1} )
728    print ${(j::)input/(#b)([^A-Za-z0-9_.!~*\'\(\)-])/%$(([##16]#match))}
729   }
730
731 # get x-lite voip software
732   getxlite() {
733     setopt local_options
734     setopt errreturn
735     [ -d ~/tmp ] || mkdir ~/tmp
736     cd ~/tmp
737     echo "Downloading http://www.counterpath.com/download/X-Lite_Install.tar.gz and storing it in ~/tmp:"
738     if wget http://www.counterpath.com/download/X-Lite_Install.tar.gz ; then
739        unp X-Lite_Install.tar.gz && echo done || echo failed
740     else
741        echo "Error while downloading." ; return 1
742     fi
743     if [ -x xten-xlite/xtensoftphone ] ; then
744        echo "Execute xten-xlite/xtensoftphone to start xlite."
745     fi
746    }
747
748 # get skype
749   getskype() {
750     setopt local_options
751     setopt errreturn
752     echo "Downloading debian package of skype."
753     echo "Notice: If you want to use a more recent skype version run 'getskypebeta'."
754     wget http://www.skype.com/go/getskype-linux-deb
755     $SUDO dpkg -i skype_debian-*.deb && echo "skype installed."
756   }
757
758 # get beta-version of skype
759   getskypebeta() {
760     setopt local_options
761     setopt errreturn
762     echo "Downloading debian package of skype (beta version)."
763     wget http://www.skype.com/go/getskype-linux-beta-deb
764     $SUDO dpkg -i skype-beta*.deb && echo "skype installed."
765   }
766
767 # get gzimo (voicp software)
768   getgizmo() {
769     setopt local_options
770     setopt errreturn
771     echo "gconf2-common and libgconf2-4 have to be available. Installing therefor."
772     $SUDO apt-get update
773     $SUDO apt-get install gconf2-common libgconf2-4
774     wget $(lynx --dump http://www.gizmoproject.com/download-linux.html | awk '/\.deb/ {print $2" "}' | tr -d '\n')
775     $SUDO dpkg -i libsipphoneapi*.deb bonjour_*.deb gizmo-*.deb && echo "gizmo installed."
776   }
777
778 # get AIR - Automated Image and Restore
779   getair() {
780     setopt local_options
781     setopt errreturn
782     [ -w . ] || { echo 'Error: you do not have write permissions in this directory. Exiting.' ; return 1 }
783     local VER='1.2.8'
784     wget http://puzzle.dl.sourceforge.net/sourceforge/air-imager/air-$VER.tar.gz
785     tar zxf air-$VER.tar.gz
786     cd air-$VER
787     INTERACTIVE=no $SUDO ./install-air-1.2.8
788     [ -x /usr/local/bin/air ] && [ -n "$DISPLAY" ] && $SUDO air
789   }
790
791 # get specific git commitdiff
792   git-get-diff() {
793     if [ -z $GITTREE ] ; then
794       GITTREE='linux/kernel/git/torvalds/linux-2.6.git'
795     fi
796     if ! [ -z $1 ] ; then
797      ${=BROWSER} "http://kernel.org/git/?p=$GITTREE;a=commitdiff;h=$1"
798     else
799       echo "Usage: git-get-diff <commit>"
800     fi
801   }
802
803 # get specific git commit
804   git-get-commit() {
805     if [ -z $GITTREE ] ; then
806       GITTREE='linux/kernel/git/torvalds/linux-2.6.git'
807     fi
808     if ! [ -z $1 ] ; then
809      ${=BROWSER} "http://kernel.org/git/?p=$GITTREE;a=commit;h=$1"
810     else
811       echo "Usage: git-get-commit <commit>"
812     fi
813   }
814
815 # get specific git diff
816   git-get-plaindiff() {
817     if [ -z $GITTREE ] ; then
818       GITTREE='linux/kernel/git/torvalds/linux-2.6.git'
819     fi
820     if ! [ -z $1 ] ; then
821       wget "http://kernel.org/git/?p=$GITTREE;a=commitdiff_plain;h=$1" -O $1.diff
822     else
823       echo 'Usage: git-get-plaindiff '
824     fi
825   }
826
827 # log 'make install' output
828 # http://strcat.de/blog/index.php?/archives/335-Software-sauber-deinstallieren...html
829   mmake() {
830     [[ ! -d ~/.errorlogs ]] && mkdir ~/.errorlogs
831     =make -n install > ~/.errorlogs/${PWD##*/}-makelog
832   }
833
834 # indent source code
835   smart-indent() {
836     indent -npro -kr -i8 -ts8 -sob -l80 -ss -ncs $*
837   }
838
839
840 # rename pictures based on information found in exif headers
841   exirename() {
842     if [ $# -lt 1 ] ; then
843        echo 'Usage: jpgrename $FILES' >& 2
844        return 1
845     else
846        echo -n 'Checking for jhead with version newer than 1.9: '
847        jhead_version=`jhead -h | grep 'used by most Digital Cameras.  v.*' | awk '{print $6}' | tr -d v`
848        if [[ $jhead_version > '1.9' ]]; then
849           echo 'success - now running jhead.'
850           jhead -n%Y-%m-%d_%Hh%M_%f $*
851        else
852           echo 'failed - exiting.'
853        fi
854     fi
855   }
856 # }}}
857
858 # mercurial related stuff {{{
859   if type -p hg >/dev/null 2>&1 ; then
860   # gnu like diff for mercurial
861   # http://www.selenic.com/mercurial/wiki/index.cgi/TipsAndTricks
862     hgdi() {
863       for i in `hg status -marn "$@"` ; diff -ubwd <(hg cat "$i") "$i"
864     }
865
866   # diffstat for specific version of mercurial
867   #   hgstat      => display diffstat between last revision and tip
868   #   hgstat 1234 => display diffstat between revision 1234 and tip
869     hgstat() {
870       [ -n "$1" ] && hg diff -r $1 -r tip | diffstat || hg export tip | diffstat
871     }
872
873   # get current mercurial tip via hg itself and install it in $HOME
874   gethgclone() {
875     setopt local_options
876     setopt errreturn
877     if [ -f mercurial-tree/.hg ] ; then
878       cd mercurial-tree
879       echo "Running hg pull for retreiving latest version..."
880       hg pull
881       echo "Finished update. Building mercurial"
882       make local
883       echo "Setting \$PATH to $PWD:\$PATH..."
884       export PATH="$PWD:$PATH"
885     else
886       echo "Downloading mercurial via hg"
887       hg clone http://selenic.com/repo/hg mercurial-tree
888       cd mercurial-tree
889       echo "Building mercurial"
890       make local
891       echo "Setting \$PATH to $PWD:\$PATH..."
892       export PATH="$PWD:$PATH"
893       echo "make sure you set it permanent via ~/.zshrc if you plan to use it permanently."
894       # echo "Setting \$PYTHONPATH to PYTHONPATH=\${HOME}/lib/python,"
895       # export PYTHONPATH=${HOME}/lib/python
896     fi
897   }
898
899   fi # end of check whether we have the 'hg'-executable
900
901   # get and install current mercurial snapshot in $HOME
902   gethgsnap() {
903     setopt local_options
904     setopt errreturn
905     if [ -f mercurial-snapshot.tar.gz ] ; then
906        echo "mercurial-snapshot.tar.gz exists already, skipping download."
907     else
908       echo "Downloading mercurial snapshot"
909       wget http://www.selenic.com/mercurial/mercurial-snapshot.tar.gz
910     fi
911     echo "Unpacking mercurial-snapshot.tar.gz"
912     tar zxf mercurial-snapshot.tar.gz
913     cd mercurial-snapshot/
914     echo "Installing required build-dependencies"
915     $SUDO apt-get update
916     $SUDO apt-get install python2.4-dev
917     echo "Building mercurial"
918     make local
919     echo "Setting \$PATH to $PWD:\$PATH..."
920     export PATH="$PWD:$PATH"
921     echo "make sure you set it permanent via ~/.zshrc if you plan to use it permanently."
922   }
923 # }}}
924
925 # some useful commands often hard to remember - let's grep for them {{{
926
927 # Work around ion/xterm resize bug.
928 #if [ "$SHLVL" = 1 ]; then
929 #       if [ -x `which resize 2>/dev/null` ]; then
930 #               eval `resize </dev/null`
931 #       fi
932 #fi
933
934 # enable jackd:
935 #  /usr/bin/jackd -dalsa -dhw:0 -r48000 -p1024 -n2
936 # now play audio file:
937 #  alsaplayer -o jack foobar.mp3
938
939 # send files via netcat
940 # on sending side:
941 #  send() {j=$*; tar cpz ${j/%${!#}/}|nc -w 1 ${!#} 51330;}
942 #  send dir* $HOST
943 #  alias receive='nc -vlp 51330 | tar xzvp'
944
945 # debian stuff:
946 # dh_make -e foo@localhost -f $1
947 # dpkg-buildpackage -rfakeroot
948 # lintian *.deb
949 # dpkg-scanpackages ./ /dev/null | gzip > Packages.gz
950 # dpkg-scansources . | gzip > Sources.gz
951 # grep-dctrl --field Maintainer $* /var/lib/apt/lists/*
952
953 # other stuff:
954 # convert -geometry 200x200 -interlace LINE -verbose
955 # ldapsearch -x -b "OU=Bedienstete,O=tug" -h ldap.tugraz.at sn=$1
956 # ps -ao user,pcpu,start,command
957 # gpg --keyserver blackhole.pca.dfn.de --recv-keys
958 # xterm -bg black -fg yellow -fn -misc-fixed-medium-r-normal--14-140-75-75-c-90-iso8859-15 -ah
959 # nc -vz $1 1-1024   # portscan via netcat
960 # wget --mirror --no-parent --convert-links
961 # pal -d `date +%d`
962 # autoload -U tetris; zle -N tetris; bindkey '...' ; echo "press ... for playing tennis"
963 #
964 # modify console cursor
965 # see http://www.tldp.org/HOWTO/Framebuffer-HOWTO-5.html
966 # print $'\e[?96;0;64c'
967 # }}}
968
969 # finally source a local zshrc {{{
970 # this allows us to stay in sync with /etc/skel/.zshrc
971 # through 'ln -s /etc/skel/.zshrc ~/.zshrc' and put own
972 # modifications in ~/.zshrc.local
973   if [ -r ~/.zshrc.local ] ; then
974      . ~/.zshrc.local
975   fi
976 # }}}
977
978 ## END OF FILE #################################################################
979 # vim:foldmethod=marker