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