* /etc/zsh/zshrc:
[grml-etc-core.git] / etc / skel / .zshrc
1 # Filename:      .zshrc
2 # Purpose:       config file for zsh
3 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
4 # Bug-Reports:   see http://grml.org/bugs/
5 # License:       This file is licensed under the GPL v2.
6 # Latest change: Don Nov 30 17:03:28 CET 2006 [mika]
7 ################################################################################
8
9 # source ~/.zshrc.global {{{
10 # see /etc/zsh/zshrc for some general settings
11 # If you don't have write permissions to /etc/zsh/zshrc on your own
12 # copy the file to your $HOME as /.zshrc.global and we source it:
13   if [ -r ~/.zshrc.global ] ; then
14      . ~/.zshrc.global
15   fi
16 # }}}
17
18 # completion system {{{
19 # just make sure it is loaded in this file too
20   type compinit &>/dev/null || { autoload -U compinit && compinit }
21 # }}}
22
23 # 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 =firefox ] && export BROWSER=firefox
39      else
40         [ -x =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
164 # use colors when browsing man pages (if not using pinfo or PAGER=most)
165   [ -d ~/.terminfo/ ] && alias man='TERMINFO=~/.terminfo/ LESS=C TERM=mostlike PAGER=less man'
166
167 # check whether Debian's package management (dpkg) is running
168   alias check_dpkg_running="$SUDO dpkg_running"
169 # }}}
170
171 ## useful functions {{{
172
173 # functions without detailed explanation:
174   agoogle() { ${=BROWSER} "http://groups.google.com/groups?as_uauthors=$*" ; }
175   bk()      { cp -b ${1} ${1}_`date --iso-8601=m` }
176   cdiff()   { diff -crd "$*" | egrep -v "^Only in |^Binary files " }
177   cl()      { cd $1 && ls -a }        # cd && ls
178   cvsa()    { cvs add $* && cvs com -m 'initial checkin' $* }
179   cvsd()    { cvs diff -N $* |& $PAGER }
180   cvsl()    { cvs log $* |& $PAGER }
181   cvsq()    { cvs -nq update }
182   cvsr()    { rcs2log $* | $PAGER }
183   cvss()    { cvs status -v $* }
184   debbug()  { ${=BROWSER} "http://bugs.debian.org/$*" }
185   debbugm() { bts show --mbox $1 } # provide bugnummer as "$1"
186   disassemble(){ gcc -pipe -S -o - -O -g $* | as -aldh -o /dev/null }
187   dmoz()    { ${=BROWSER} http://search.dmoz.org/cgi-bin/search\?search=${1// /_} }
188   dwicti()  { ${=BROWSER} http://de.wiktionary.org/wiki/${(C)1// /_} }
189   ewicti()  { ${=BROWSER} http://en.wiktionary.org/wiki/${(C)1// /_} }
190   fir()     { firefox -a firefox -remote "openURL($1)" }
191   ggogle()  { ${=BROWSER} "http://groups.google.com/groups?q=$*" }
192   google()  { ${=BROWSER} "http://www.google.com/search?&num=100&q=$*" }
193   mdiff()   { diff -udrP "$1" "$2" > diff.`date "+%Y-%m-%d"`."$1" }
194   memusage(){ ps aux | awk '{if (NR > 1) print $5; if (NR > 2) print "+"} END { print "p" }' | dc }
195   mggogle() { ${=BROWSER} "http://groups.google.com/groups?selm=$*" }
196   netcraft(){ ${=BROWSER} "http://toolbar.netcraft.com/site_report?url=$1" }
197   oleo()    { ${=BROWSER} "http://dict.leo.org/?search=$*" }
198   shtar()   { gunzip -c $1 | tar -tf - -- | $PAGER }
199   shtgz()   { tar -ztf $1 | $PAGER }
200   shzip()   { unzip -l $1 | $PAGER }
201   sig()     { agrep -d '^-- $' "$*" ~/.Signature }
202   swiki()   { ${=BROWSER} http://de.wikipedia.org/wiki/Spezial:Search/${(C)1} }
203   udiff()   { diff -urd $* | egrep -v "^Only in |^Binary files " }
204   viless()  { vim --cmd 'let no_plugin_maps = 1' -c "so \$VIMRUNTIME/macros/less.vim" "${@:--}" }
205   wikide () { ${=BROWSER} http://de.wikipedia.org/wiki/"${(C)*}" }
206   wikien()  { ${=BROWSER} http://en.wikipedia.org/wiki/"$*" }
207   wodeb ()  { ${=BROWSER} "http://packages.debian.org/cgi-bin/search_contents.pl?word=$1&version=${2:-unstable}" }
208
209   which google &>/dev/null && gex () { google "\"[ $1]\" $*" } # exact search at google
210
211 # Function Usage: doc packagename
212   doc() { cd /usr/share/doc/$1 && ls }
213   _doc() { _files -W /usr/share/doc -/ }
214   compdef _doc doc
215
216 # make screenshot of current desktop (use 'import' from ImageMagic)
217   sshot() {
218         [[ ! -d ~/shots  ]] && mkdir ~/shots
219         #cd ~/shots ; sleep 5 ; import -window root -depth 8 -quality 80 `date "+%Y-%m-%d--%H:%M:%S"`.png
220         cd ~/shots ; sleep 5; import -window root shot_`date --iso-8601=m`.jpg
221   }
222
223 # list images only
224   limg() {
225     local -a images
226     images=( *.{jpg,gif,png}(.N) )
227     if [[ $#images -eq 0 ]] ; then
228       print "No image files found"
229     else
230       ls "$@" "$images[@]"
231     fi
232   }
233
234 # create pdf file from source code
235   makereadable() {
236      output=$1
237      shift
238      a2ps --medium A4dj -E -o $output $*
239      ps2pdf $output
240   }
241
242 # zsh with perl-regex - use it e.g. via:
243 # regcheck '\s\d\.\d{3}\.\d{3} Euro' ' 1.000.000 Euro'
244   regcheck() {
245     zmodload -i zsh/pcre
246     pcre_compile $1 && \
247     pcre_match $2 && echo "regex matches" || echo "regex does not match"
248   }
249
250 # list files which have been modified within the last x days
251   new() { print -l *(m-$1) }
252
253 # grep the history
254   greph () { history 0 | grep $1 }
255   (grep --help 2>/dev/null |grep -- --color) >/dev/null && \
256     alias grep='grep --color=auto' # use colors when GNU grep with color-support
257   alias GREP='grep -i --color=auto'
258
259 # one blank line between each line
260   if [ -r ~/.terminfo/m/mostlike ] ; then
261 #     alias man2='MANPAGER="sed -e G |less" TERMINFO=~/.terminfo TERM=mostlike /usr/bin/man'
262      man2() { PAGER='dash -c "sed G | /usr/bin/less"' TERM=mostlike /usr/bin/man "$@" ; }
263   fi
264
265 # jump between directories
266 # Copyright 2005 Nikolai Weibull <nikolai@bitwi.se>
267 # notice: option AUTO_PUSHD has to be set
268   d(){
269     emulate -L zsh
270     autoload -U colors
271     local color=$fg_bold[blue]
272     integer i=0
273     dirs -p | while read dir; do
274       local num="${$(printf "%-4d " $i)/ /.}"
275       printf " %s  $color%s$reset_color\n" $num $dir
276       (( i++ ))
277     done
278     integer dir=-1
279     read -r 'dir?Jump to directory: ' || return
280     (( dir == -1 )) && return
281     if (( dir < 0 || dir >= i )); then
282       echo d: no such directory stack entry: $dir
283       return 1
284     fi
285     cd ~$dir
286   }
287
288 # find out which libs define a symbol
289 # usage example: 'lcheck strcpy'
290   lcheck() {
291      if [ -n "$1" ] ; then
292         nm -go /usr/lib/lib*.a 2>/dev/null | grep ":[[:xdigit:]]\{8\} . .*$1"
293       else
294         echo "Usage: lcheck <function>" >&2
295      fi
296   }
297
298 # clean up directory
299   purge() {
300         FILES=(*~(N) .*~(N) \#*\#(N) *.o(N) a.out(N) *.core(N) *.cmo(N) *.cmi(N) .*.swp(N))
301         NBFILES=${#FILES}
302         if [[ $NBFILES > 0 ]]; then
303                 print $FILES
304                 local ans
305                 echo -n "Remove these files? [y/n] "
306                 read -q ans
307                 if [[ $ans == "y" ]]
308                 then
309                         rm ${FILES}
310                         echo ">> $PWD purged, $NBFILES files removed"
311                 else
312                         echo "Ok. .. than not.."
313                 fi
314         fi
315    }
316
317 # Translate DE<=>EN
318 # 'translate' looks up fot a word in a file with language-to-language
319 # translations (field separator should be " : "). A typical wordlist looks
320 # like at follows:
321 #  | english-word : german-transmission
322 # It's also only possible to translate english to german but not reciprocal.
323 # Use the following oneliner to turn back the sort order:
324 #  $ awk -F ':' '{ print $2" : "$1" "$3 }' \
325 #    /usr/local/lib/words/en-de.ISO-8859-1.vok > ~/.translate/de-en.ISO-8859-1.vok
326   trans() {
327         case "$1" in
328                 -[dD]*) translate -l de-en $2
329                 ;;
330                 -[eE]*) translate -l en-de $2
331                 ;;
332                 *)
333                 echo "Usage: $0 { -D | -E }"
334                 echo "         -D == German to English"
335                 echo "         -E == English to German"
336         esac
337   }
338
339 # Some quick Perl-hacks aka /useful/ oneliner
340 #  bew() { perl -le 'print unpack "B*","'$1'"' }
341 #  web() { perl -le 'print pack "B*","'$1'"' }
342 #  hew() { perl -le 'print unpack "H*","'$1'"' }
343 #  weh() { perl -le 'print pack "H*","'$1'"' }
344 #  pversion()    { perl -M$1 -le "print $1->VERSION" } # i. e."pversion LWP -> 5.79"
345 #  getlinks ()   { perl -ne 'while ( m/"((www|ftp|http):\/\/.*?)"/gc ) { print $1, "\n"; }' $* }
346 #  gethrefs ()   { perl -ne 'while ( m/href="([^"]*)"/gc ) { print $1, "\n"; }' $* }
347 #  getanames ()  { perl -ne 'while ( m/a name="([^"]*)"/gc ) { print $1, "\n"; }' $* }
348 #  getforms ()   { perl -ne 'while ( m:(\</?(input|form|select|option).*?\>):gic ) { print $1, "\n"; }' $* }
349 #  getstrings () { perl -ne 'while ( m/"(.*?)"/gc ) { print $1, "\n"; }' $*}
350 #  getanchors () { perl -ne 'while ( m/«([^«»\n]+)»/gc ) { print $1, "\n"; }' $* }
351 #  showINC ()    { perl -e 'for (@INC) { printf "%d %s\n", $i++, $_ }' }
352 #  vimpm ()      { vim `perldoc -l $1 | sed -e 's/pod$/pm/'` }
353 #  vimhelp ()    { vim -c "help $1" -c on -c "au! VimEnter *" }
354
355 # plap foo -- list all occurrences of program in the current PATH
356   plap() {
357         if [[ $# = 0 ]]
358         then
359                 echo "Usage:    $0 program"
360                 echo "Example:  $0 zsh"
361                 echo "Lists all occurrences of program in the current PATH."
362         else
363                 ls -l ${^path}/*$1*(*N)
364         fi
365   }
366
367 # Found in the mailinglistarchive from Zsh (IIRC ~1996)
368   selhist() {
369         emulate -L zsh
370         local TAB=$'\t';
371         (( $# < 1 )) && {
372                 echo "Usage: $0 command"
373                 return 1
374         };
375         cmd=(${(f)"$(grep -w $1 $HISTFILE | sort | uniq | pr -tn)"})
376         print -l $cmd | less -F
377         echo -n "enter number of desired command [1 - $(( ${#cmd[@]} - 1 ))]: "
378         local answer
379         read answer
380         print -z "${cmd[$answer]#*$TAB}"
381   }
382
383 # mkdir && cd
384   mcd() { mkdir -p "$@"; cd "$@" }  # mkdir && cd
385
386 # cd && ls
387   cl() { cd $1 && ls -a }
388
389 # Use vim to convert plaintext to HTML
390   2html() { vim -u NONE -n -c ':syntax on' -c ':so $VIMRUNTIME/syntax/2html.vim' -c ':wqa' $1 &>/dev/null }
391
392 # Usage: simple-extract <file>
393 # Description: extracts archived files (maybe)
394   simple-extract () {
395         if [[ -f $1 ]]
396         then
397                 case $1 in
398                         *.tar.bz2)  bzip2 -v -d $1      ;;
399                         *.tar.gz)   tar -xvzf $1        ;;
400                         *.rar)      unrar $1            ;;
401                         *.deb)      ar -x $1            ;;
402                         *.bz2)      bzip2 -d $1         ;;
403                         *.lzh)      lha x $1            ;;
404                         *.gz)       gunzip -d $1        ;;
405                         *.tar)      tar -xvf $1         ;;
406                         *.tgz)      gunzip -d $1        ;;
407                         *.tbz2)     tar -jxvf $1        ;;
408                         *.zip)      unzip $1            ;;
409                         *.Z)        uncompress $1       ;;
410                         *)          echo "'$1' Error. Please go away" ;;
411                 esac
412         else
413                 echo "'$1' is not a valid file"
414         fi
415   }
416
417 # Usage: smartcompress <file> (<type>)
418 # Description: compresses files or a directory.  Defaults to tar.gz
419   smartcompress() {
420         if [ $2 ]; then
421                 case $2 in
422                         tgz | tar.gz)   tar -zcvf$1.$2 $1 ;;
423                         tbz2 | tar.bz2) tar -jcvf$1.$2 $1 ;;
424                         tar.Z)          tar -Zcvf$1.$2 $1 ;;
425                         tar)            tar -cvf$1.$2  $1 ;;
426                         gz | gzip)      gzip           $1 ;;
427                         bz2 | bzip2)    bzip2          $1 ;;
428                         *)
429                         echo "Error: $2 is not a valid compression type"
430                         ;;
431                 esac
432         else
433                 smartcompress $1 tar.gz
434         fi
435   }
436
437 # Usage: show-archive <archive>
438 # Description: view archive without unpack
439   show-archive() {
440         if [[ -f $1 ]]
441         then
442                 case $1 in
443                         *.tar.gz)      gunzip -c $1 | tar -tf - -- ;;
444                         *.tar)         tar -tf $1 ;;
445                         *.tgz)         tar -ztf $1 ;;
446                         *.zip)         unzip -l $1 ;;
447                         *.bz2)         bzless $1 ;;
448                         *)             echo "'$1' Error. Please go away" ;;
449                 esac
450         else
451                 echo "'$1' is not a valid archive"
452         fi
453   }
454
455 # follow symlinks
456   folsym() {
457     if [[ -e $1 || -h $1 ]]; then
458         file=$1
459     else
460         file=`which $1`
461     fi
462     if [[ -e $file || -L $file ]]; then
463         if [[ -L $file ]]; then
464             echo `ls -ld $file | perl -ane 'print $F[7]'` '->'
465             folsym `perl -le '$file = $ARGV[0];
466                               $dest = readlink $file;
467                               if ($dest !~ m{^/}) {
468                                   $file =~ s{(/?)[^/]*$}{$1$dest};
469                               } else {
470                                   $file = $dest;
471                               }
472                               $file =~ s{/{2,}}{/}g;
473                               while ($file =~ s{[^/]+/\.\./}{}) {
474                                   ;
475                               }
476                               $file =~ s{^(/\.\.)+}{};
477                               print $file' $file`
478         else
479             ls -d $file
480         fi
481     else
482         echo $file
483     fi
484   }
485
486 # Use 'view' to read manpages, if u want colors, regex - search, ...
487 # like vi(m).
488 # It's shameless stolen from <http://www.vim.org/tips/tip.php?tip_id=167>
489   vman() { man $* | col -b | view -c 'set ft=man nomod nolist' - }
490
491 # search for various types or README file in dir and display them in $PAGER
492 # function readme() { $PAGER -- (#ia3)readme* }
493   readme() {
494         local files
495         files=(./(#i)*(read*me|lue*m(in|)ut)*(ND))
496         if (($#files))
497         then $PAGER $files
498         else
499                 print 'No README files.'
500         fi
501   }
502
503 # find all suid files in $PATH
504 # suidfind() { ls -latg $path | grep '^...s' }
505   suidfind() { ls -latg $path/*(sN) }
506
507 # See above but this is /better/ ... anywise ..
508   findsuid() {
509     print 'Output will be written to ~/suid_* ...'
510     $SUDO find / -type f \( -perm -4000 -o -perm -2000 \) -ls > ~/suid_suidfiles.`date "+%Y-%m-%d"`.out 2>&1
511     $SUDO find / -type d \( -perm -4000 -o -perm -2000 \) -ls > ~/suid_suiddirs.`date "+%Y-%m-%d"`.out 2>&1
512     $SUDO find / -type f \( -perm -2 -o -perm -20 \) -ls > ~/suid_writefiles.`date "+%Y-%m-%d"`.out 2>&1
513     $SUDO find / -type d \( -perm -2 -o -perm -20 \) -ls > ~/suid_writedirs.`date "+%Y-%m-%d"`.out 2>&1
514     print 'Finished'
515   }
516
517 # Reload functions.
518   refunc() {
519         for func in $argv
520         do
521                 unfunction $func
522                 autoload $func
523         done
524   }
525
526 # a small check to see which DIR is located on which server/partition.
527 # stolen and modified from Sven's zshrc.forall
528   dirspace() {
529     if [ -n "$1" ] ; then
530        for dir in $* ; do
531           if [ -d "$dir" ] ; then
532              ( cd $dir; echo "-<$dir>"; du -shx .; echo);
533           else
534              echo "warning: $dir does not exist" >&2
535           fi
536        done
537     else
538         for dir in $path; do
539           if [ -d "$dir" ] ; then
540              ( cd $dir; echo "-<$dir>"; du -shx .; echo);
541           else
542              echo "warning: $dir does not exist" >&2
543           fi
544         done
545     fi
546   }
547
548 # % slow_print `cat /etc/passwd`
549   slow_print() {
550         for argument in "${@}"
551         do
552                 for ((i = 1; i <= ${#1} ;i++)) {
553                         print -n "${argument[i]}"
554                         sleep 0.08
555                 }
556                 print -n " "
557         done
558         print ""
559   }
560
561 # display system state
562   status() {
563         print ""
564         print "Date..: "$(date "+%Y-%m-%d %H:%M:%S")""
565         print "Shell.: Zsh $ZSH_VERSION (PID = $$, $SHLVL nests)"
566         print "Term..: $TTY ($TERM), $BAUD bauds, $COLUMNS x $LINES cars"
567         print "Login.: $LOGNAME (UID = $EUID) on $HOST"
568         print "System: $(cat /etc/[A-Za-z]*[_-][rv]e[lr]*)"
569         print "Uptime:$(uptime)"
570         print ""
571   }
572
573 # Rip an audio CD
574   audiorip() {
575         mkdir -p ~/ripps
576         cd ~/ripps
577         cdrdao read-cd --device $DEVICE --driver generic-mmc audiocd.toc
578         cdrdao read-cddb --device $DEVICE --driver generic-mmc audiocd.toc
579         echo " * Would you like to burn the cd now? (yes/no)"
580         read input
581         if
582                 [ "$input" = "yes" ]; then
583                 echo " ! Burning Audio CD"
584                 audioburn
585                 echo " * done."
586         else
587                 echo " ! Invalid response."
588         fi
589   }
590
591 # and burn it
592   audioburn() {
593         cd ~/ripps
594         cdrdao write --device $DEVICE --driver generic-mmc audiocd.toc
595         echo " * Should I remove the temporary files? (yes/no)"
596         read input
597         if [ "$input" = "yes" ]; then
598                 echo " ! Removing Temporary Files."
599                 cd ~
600                 rm -rf ~/ripps
601                 echo " * done."
602         else
603                 echo " ! Invalid response."
604         fi
605   }
606
607 # Make an audio CD from all mp3 files
608   mkaudiocd() {
609         cd ~/ripps
610         for i in *.[Mm][Pp]3; do mv "$i" `echo $i | tr '[A-Z]' '[a-z]'`; done
611         for i in *.mp3; do mv "$i" `echo $i | tr ' ' '_'`; done
612         for i in *.mp3; do mpg123 -w `basename $i .mp3`.wav $i; done
613         normalize -m *.wav
614         for i in *.wav; do sox $i.wav -r 44100 $i.wav resample; done
615   }
616
617 # Create an ISO image. You are prompted for volume name, filename and directory
618   mkiso() {
619         echo " * Volume name "
620         read volume
621         echo " * ISO Name (ie. tmp.iso)"
622         read iso
623         echo " * Directory or File"
624         read files
625         mkisofs -o ~/$iso -A $volume -allow-multidot -J -R -iso-level 3 -V $volume -R $files
626   }
627
628 # simple thumbnails generator
629   genthumbs () {
630     rm -rf thumb-* index.html
631     echo "
632 <html>
633   <head>
634     <title>Images</title>
635   </head>
636   <body>" > index.html
637     for f in *.(gif|jpeg|jpg|png)
638     do
639         convert -size 100x200 "$f" -resize 100x200 thumb-"$f"
640         echo "    <a href=\"$f\"><img src=\"thumb-$f\"></a>" >> index.html
641     done
642     echo "
643   </body>
644 </html>" >> index.html
645   }
646
647 # unset all limits (see zshbuiltins(1) /ulimit for details)
648   allulimit() {
649     ulimit -c unlimited
650     ulimit -d unlimited
651     ulimit -f unlimited
652     ulimit -l unlimited
653     ulimit -n unlimited
654     ulimit -s unlimited
655     ulimit -t unlimited
656   }
657
658 # ogg2mp3 with bitrate of 192
659   ogg2mp3_192() {
660     oggdec -o - ${1} | lame -b 192 - ${1:r}.mp3
661   }
662
663 # RFC 2396 URL encoding in Z-Shell
664   urlencode() {
665    setopt localoptions extendedglob
666    input=( ${(s::)1} )
667    print ${(j::)input/(#b)([^A-Za-z0-9_.!~*\'\(\)-])/%$(([##16]#match))}
668   }
669
670 # get x-lite voip software
671   getxlite() {
672     setopt local_options
673     setopt errreturn
674     [ -d ~/tmp ] || mkdir ~/tmp
675     cd ~/tmp
676     echo "Downloading http://www.counterpath.com/download/X-Lite_Install.tar.gz and storing it in ~/tmp:"
677     if wget http://www.counterpath.com/download/X-Lite_Install.tar.gz ; then
678        unp X-Lite_Install.tar.gz && echo done || echo failed
679     else
680        echo "Error while downloading." ; return 1
681     fi
682     if [ -x xten-xlite/xtensoftphone ] ; then
683        echo "Execute xten-xlite/xtensoftphone to start xlite."
684     fi
685    }
686
687 # get skype
688   getskype() {
689     setopt local_options
690     setopt errreturn
691     echo "Downloading debian package of skype."
692     echo "Notice: If you want to use a more recent skype version run 'getskypebeta'."
693     wget http://www.skype.com/go/getskype-linux-deb
694     $SUDO dpkg -i skype_debian-*.deb && echo "skype installed."
695   }
696
697 # get beta-version of skype
698   getskypebeta() {
699     setopt local_options
700     setopt errreturn
701     echo "Downloading debian package of skype (beta version)."
702     wget http://www.skype.com/go/getskype-linux-beta-deb
703     $SUDO dpkg -i skype-beta*.deb && echo "skype installed."
704   }
705
706 # get gzimo (VoIP software)
707   getgizmo() {
708     setopt local_options
709     setopt errreturn
710     echo "gconf2-common and libgconf2-4 have to be available. Installing therefor."
711     $SUDO apt-get update
712     $SUDO apt-get install gconf2-common libgconf2-4
713     wget $(lynx --dump http://www.gizmoproject.com/download-linux.html | awk '/\.deb/ {print $2" "}' | tr -d '\n')
714     $SUDO dpkg -i libsipphoneapi*.deb bonjour_*.deb gizmo-*.deb && echo "gizmo installed."
715   }
716
717 # get AIR - Automated Image and Restore
718   getair() {
719     setopt local_options
720     setopt errreturn
721     [ -w . ] || { echo 'Error: you do not have write permissions in this directory. Exiting.' ; return 1 }
722     local VER='1.2.8'
723     wget http://puzzle.dl.sourceforge.net/sourceforge/air-imager/air-$VER.tar.gz
724     tar zxf air-$VER.tar.gz
725     cd air-$VER
726     INTERACTIVE=no $SUDO ./install-air-1.2.8
727     [ -x /usr/local/bin/air ] && [ -n "$DISPLAY" ] && $SUDO air
728   }
729
730 # get specific git commitdiff
731   git-get-diff() {
732     if [ -z $GITTREE ] ; then
733       GITTREE='linux/kernel/git/torvalds/linux-2.6.git'
734     fi
735     if ! [ -z $1 ] ; then
736      ${=BROWSER} "http://kernel.org/git/?p=$GITTREE;a=commitdiff;h=$1"
737     else
738       echo "Usage: git-get-diff <commit>"
739     fi
740   }
741
742 # get specific git commit
743   git-get-commit() {
744     if [ -z $GITTREE ] ; then
745       GITTREE='linux/kernel/git/torvalds/linux-2.6.git'
746     fi
747     if ! [ -z $1 ] ; then
748      ${=BROWSER} "http://kernel.org/git/?p=$GITTREE;a=commit;h=$1"
749     else
750       echo "Usage: git-get-commit <commit>"
751     fi
752   }
753
754 # get specific git diff
755   git-get-plaindiff() {
756     if [ -z $GITTREE ] ; then
757       GITTREE='linux/kernel/git/torvalds/linux-2.6.git'
758     fi
759     if ! [ -z $1 ] ; then
760       wget "http://kernel.org/git/?p=$GITTREE;a=commitdiff_plain;h=$1" -O $1.diff
761     else
762       echo 'Usage: git-get-plaindiff '
763     fi
764   }
765
766 # log 'make install' output
767 # http://strcat.de/blog/index.php?/archives/335-Software-sauber-deinstallieren...html
768   mmake() {
769     [[ ! -d ~/.errorlogs ]] && mkdir ~/.errorlogs
770     =make -n install > ~/.errorlogs/${PWD##*/}-makelog
771   }
772
773 # indent source code
774   smart-indent() {
775     indent -npro -kr -i8 -ts8 -sob -l80 -ss -ncs $*
776   }
777
778 # highlight important stuff in diff output, usage example: hg diff | hidiff
779   [ -x =histring ] && \
780   alias hidiff="histring -fE '^Comparing files .*|^diff .*' | histring -c yellow -fE '^\-.*' | histring -c green -fE '^\+.*'"
781
782 # rename pictures based on information found in exif headers
783   exirename() {
784     if [ $# -lt 1 ] ; then
785        echo 'Usage: jpgrename $FILES' >& 2
786        return 1
787     else
788        echo -n 'Checking for jhead with version newer than 1.9: '
789        jhead_version=`jhead -h | grep 'used by most Digital Cameras.  v.*' | awk '{print $6}' | tr -d v`
790        if [[ $jhead_version > '1.9' ]]; then
791           echo 'success - now running jhead.'
792           jhead -n%Y-%m-%d_%Hh%M_%f $*
793        else
794           echo 'failed - exiting.'
795        fi
796     fi
797   }
798 # }}}
799
800 # mercurial related stuff {{{
801   if type -p hg &>/dev/null ; then
802   # gnu like diff for mercurial
803   # http://www.selenic.com/mercurial/wiki/index.cgi/TipsAndTricks
804     hgdi() {
805       for i in `hg status -marn "$@"` ; diff -ubwd <(hg cat "$i") "$i"
806     }
807
808   # build debian package
809     alias hbp='hg-buildpackage'
810
811   # diffstat for specific version of a mercurial repository
812   #   hgstat      => display diffstat between last revision and tip
813   #   hgstat 1234 => display diffstat between revision 1234 and tip
814     hgstat() {
815       [ -n "$1" ] && hg diff -r $1 -r tip | diffstat || hg export tip | diffstat
816     }
817
818   # get current mercurial tip via hg itself
819     gethgclone() {
820       setopt local_options
821       setopt errreturn
822       if [ -f mercurial-tree/.hg ] ; then
823         cd mercurial-tree
824         echo "Running hg pull for retreiving latest version..."
825         hg pull
826         echo "Finished update. Building mercurial"
827         make local
828         echo "Setting \$PATH to $PWD:\$PATH..."
829         export PATH="$PWD:$PATH"
830       else
831         echo "Downloading mercurial via hg"
832         hg clone http://selenic.com/repo/hg mercurial-tree
833         cd mercurial-tree
834         echo "Building mercurial"
835         make local
836         echo "Setting \$PATH to $PWD:\$PATH..."
837         export PATH="$PWD:$PATH"
838         echo "make sure you set it permanent via ~/.zshrc if you plan to use it permanently."
839         # echo "Setting \$PYTHONPATH to PYTHONPATH=\${HOME}/lib/python,"
840         # export PYTHONPATH=${HOME}/lib/python
841       fi
842     }
843
844   fi # end of check whether we have the 'hg'-executable
845
846   # get current mercurial snapshot
847     gethgsnap() {
848       setopt local_options
849       setopt errreturn
850       if [ -f mercurial-snapshot.tar.gz ] ; then
851          echo "mercurial-snapshot.tar.gz exists already, skipping download."
852       else
853         echo "Downloading mercurial snapshot"
854         wget http://www.selenic.com/mercurial/mercurial-snapshot.tar.gz
855       fi
856       echo "Unpacking mercurial-snapshot.tar.gz"
857       tar zxf mercurial-snapshot.tar.gz
858       cd mercurial-snapshot/
859       echo "Installing required build-dependencies"
860       $SUDO apt-get update
861       $SUDO apt-get install python2.4-dev
862       echo "Building mercurial"
863       make local
864       echo "Setting \$PATH to $PWD:\$PATH..."
865       export PATH="$PWD:$PATH"
866       echo "make sure you set it permanent via ~/.zshrc if you plan to use it permanently."
867     }
868 # }}}
869
870 # some useful commands often hard to remember - let's grep for them {{{
871
872 # Work around ion/xterm resize bug.
873 #if [ "$SHLVL" = 1 ]; then
874 #       if [ -x `which resize 2>/dev/null` ]; then
875 #               eval `resize </dev/null`
876 #       fi
877 #fi
878
879 # enable jackd:
880 #  /usr/bin/jackd -dalsa -dhw:0 -r48000 -p1024 -n2
881 # now play audio file:
882 #  alsaplayer -o jack foobar.mp3
883
884 # send files via netcat
885 # on sending side:
886 #  send() {j=$*; tar cpz ${j/%${!#}/}|nc -w 1 ${!#} 51330;}
887 #  send dir* $HOST
888 #  alias receive='nc -vlp 51330 | tar xzvp'
889
890 # debian stuff:
891 # dh_make -e foo@localhost -f $1
892 # dpkg-buildpackage -rfakeroot
893 # lintian *.deb
894 # dpkg-scanpackages ./ /dev/null | gzip > Packages.gz
895 # dpkg-scansources . | gzip > Sources.gz
896 # grep-dctrl --field Maintainer $* /var/lib/apt/lists/*
897
898 # other stuff:
899 # convert -geometry 200x200 -interlace LINE -verbose
900 # ldapsearch -x -b "OU=Bedienstete,O=tug" -h ldap.tugraz.at sn=$1
901 # ps -ao user,pcpu,start,command
902 # gpg --keyserver blackhole.pca.dfn.de --recv-keys
903 # xterm -bg black -fg yellow -fn -misc-fixed-medium-r-normal--14-140-75-75-c-90-iso8859-15 -ah
904 # nc -vz $1 1-1024   # portscan via netcat
905 # wget --mirror --no-parent --convert-links
906 # pal -d `date +%d`
907 # autoload -U tetris; zle -N tetris; bindkey '...' ; echo "press ... for playing tennis"
908 #
909 # modify console cursor
910 # see http://www.tldp.org/HOWTO/Framebuffer-HOWTO-5.html
911 # print $'\e[?96;0;64c'
912 # }}}
913
914 # finally source a local zshrc and grmlsmall-specific configuration {{{
915
916 # The following file is used to remove zsh-config-items that do not work
917 # in grml-small by default.
918 # If you do not want these adjustments (for whatever reason),
919 # there are three ways to accomplish that:
920 #  a) at the beginning of this file (variables section), set
921 #     $GRMLSMALL_SPECIFIC to 0 or comment out the variable definition.
922 #  b) remove/rename .zshrc.grmlsmall
923 #  c) comment out the following line
924   (( GRMLSMALL_SPECIFIC > 0 )) && isgrmlsmall && source ~/.zshrc.grmlsmall
925
926 # this allows us to stay in sync with /etc/skel/.zshrc
927 # through 'ln -s /etc/skel/.zshrc ~/.zshrc' and put own
928 # modifications in ~/.zshrc.local
929   if [ -r ~/.zshrc.local ] ; then
930      . ~/.zshrc.local
931   fi
932 # }}}
933
934 ## END OF FILE #################################################################
935 # vim:foldmethod=marker