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