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