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