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