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