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