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