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