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