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