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