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