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