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