drop unwanted bindkey stuff in power completion, thanks ft
[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 Nov 12 11:30:30 CET 2006 [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 [ -r ~/.zshrc.global ] ; then
14      . ~/.zshrc.global
15   fi
16 # }}}
17
18 # completion system {{{
19 # just make sure it is loaded in this file too
20   type compinit &>/dev/null || { autoload -U compinit && compinit }
21 # }}}
22
23 ## variables {{{
24
25 # set terminal property (used e.g. by msgid-chooser)
26   export COLORTERM="yes"
27
28 # set default browser
29   if [ -z $BROWSER ] ; then
30      if [ -n "$DISPLAY" ] ; then
31         [ -x =firefox ] && export BROWSER=firefox
32      else
33         [ -x =w3m ] && export BROWSER=w3m
34      fi
35   fi
36   (( ${+PAGER} ))   || export PAGER="less"
37
38 # export qtdir
39   [ -d /usr/share/qt3 ] && export QTDIR=/usr/share/qt3
40   [ -d /usr/share/qt4 ] && export QTDIR=/usr/share/qt4
41
42 # support running 'jikes *.java && jamvm HelloWorld' OOTB:
43   [ -f /usr/share/classpath/glibj.zip ] && export JIKESPATH=/usr/share/classpath/glibj.zip
44 # }}}
45
46 ## set options {{{
47
48 # Allow comments even in interactive shells i. e.
49 # $ uname # This command prints system informations
50 # zsh: bad pattern: #
51 # $ setopt interactivecomments
52 # $ uname # This command prints system informations
53 # Linux
54 #  setopt interactivecomments
55
56 # ctrl-s will no longer freeze the terminal.
57 #  stty erase "^?"
58
59 # }}}
60
61 # {{{ global aliases
62 # These do not have to be at the beginning of the command line.
63 # Avoid typing cd ../../ for going two dirs down and so on
64 # Usage, e.g.: "$ cd ...' or just '$ ...' with 'setopt auto_cd'
65 # Notice: deactivated by 061112 by default, use another approach - see 'power completion'
66 #  alias -g '...'='../..'
67 #  alias -g '....'='../../..'
68 #  alias -g BG='& exit'
69 #  alias -g C='|wc -l'
70 #  alias -g G='|grep'
71 #  alias -g H='|head'
72 #  alias -g Hl=' --help |& less -r'
73 #  alias -g K='|keep'
74 #  alias -g L='|less'
75 #  alias -g LL='|& less -r'
76 #  alias -g M='|most'
77 #  alias -g N='&>/dev/null'
78 #  alias -g R='| tr A-z N-za-m'
79 #  alias -g SL='| sort | less'
80 #  alias -g S='| sort'
81 #  alias -g T='|tail'
82 #  alias -g V='| vim -'
83
84 # power completion, see http://zshwiki.org/home/examples/zleiab
85 # less risky than the global aliases but powerful as well
86 # just type the abbreviation key and afterwards ',.' to expand it
87   declare -A abk
88   setopt extendedglob
89   setopt interactivecomments
90   abk=(
91    # key  # value
92    'C'    '| wc -l'
93    '...' '../..'
94    '....' '../../..'
95    'BG' '& exit'
96    'C' '|wc -l'
97    'G' '|& grep --color=auto'
98    'H' '|head'
99    'Hl' ' --help |& less -r'
100    'L' '|less'
101    'LL' '|& less -r'
102    'M' '|most'
103    'N' '&>/dev/null'
104    'R' '| tr A-z N-za-m'
105    'SL' '| sort | less'
106    'S' '| sort -u'
107    'T' '|tail'
108    'V' '|& vim -'
109    'hide' "echo -en '\033]50;nil2\007'"
110    'tiny' 'echo -en "\033]50;-misc-fixed-medium-r-normal-*-*-80-*-*-c-*-iso8859-15\007"'
111    'small' 'echo -en "\033]50;6x10\007"'
112    'medium' 'echo -en "\033]50;-misc-fixed-medium-r-normal--13-120-75-75-c-80-iso8859-15\007"'
113    'default' 'echo -e "\033]50;-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-15\007"'
114    'large' 'echo -en "\033]50;-misc-fixed-medium-r-normal-*-*-150-*-*-c-*-iso8859-15\007"'
115    'huge' 'echo -en "\033]50;-misc-fixed-medium-r-normal-*-*-210-*-*-c-*-iso8859-15\007"'
116    'smartfont' 'echo -en "\033]50;-artwiz-smoothansi-*-*-*-*-*-*-*-*-*-*-*-*\007"'
117    'semifont' 'echo -en "\033]50;-misc-fixed-medium-r-semicondensed-*-*-120-*-*-*-*-iso8859-15\007"'
118    'da' 'du -sch'
119    'j' 'jobs -l'
120    'u' 'translate -i'
121    'co' "./configure && make && sudo make install"
122    'CH' "./configure --help"
123    'conkeror' 'firefox -chrome chrome://conkeror/content'
124    'dir' 'ls -lSrah'
125    'lad' $'ls -d .*(/)\n# only show dot-directories'
126    'lsa' $'ls -a .*(.)\n# only show dot-files'
127    'lss' $'ls -l *(s,S,t)\n# only files with setgid/setuid/sticky flag'
128    'lsl' $'ls -l *(@[1,10])\n# only symlinks'
129    'lsx' $'ls -l *(*[1,10])\n# only executables'
130    'lsw' $'ls -ld *(R,W,X.^ND/)\n# world-{readable,writable,executable} files'
131    'lsbig' $'ls -flh *(.OL[1,10])\n# display the biggest files'
132    'lsd' $'ls -d *(/)\n# only show directories'
133    'lse' $'ls -d *(/^F)\n# only show empty directories'
134    'lsnew' $'ls -rl *(D.om[1,10])\n# display the newest files'
135    'lsold' $'ls -rtlh *(D.om[-11,-1])\n # display the oldest files'
136    'lssmall' $'ls -Srl *(.oL[1,10])\n# display the smallest files'
137    'rw-' 'chmod 600'
138    '600' 'chmod u+rw-x,g-rwx,o-rwx'
139    'rwx' 'chmod u+rwx'
140    '700' 'chmod u+rwx,g-rwx,o-rwx'
141    'r--' 'chmod u+r-wx,g-rwx,o-rwx'
142    '644' $'chmod u+rw-x,g+r-wx,o+r-wx\n # 4=r,2=w,1=x'
143    '755' 'chmod u+rwx,g+r-w+x,o+r-w+x'
144    'md' 'mkdir -p '
145    'cmplayer' 'mplayer -vo -fs -zoom fbdev'
146    'fbmplayer' 'mplayer -vo -fs -zoom fbdev'
147    'fblinks' 'links2 -driver fb'
148    'insecssh' 'ssh -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=/dev/null"'
149    'fori' 'for i ({..}) { }'
150    'cx' 'chmod +x'
151    'e'  'print -l'
152    'se' 'setopt interactivecomments'
153    'va' 'valac --vapidir=../vapi/ --pkg=gtk+-2.0 gtktest.vala'
154    'fb2' '=mplayer -vo fbdev -fs -zoom 1>/dev/null -xy 2'
155    'fb3' '=mplayer -vo fbdev -fs  -zoom 1>/dev/null -xy 3'
156    'ci' 'centericq'
157    'D'  'export DISPLAY=:0.0'
158    'mp' 'mplayer -vo xv -fs -zoom'
159   )
160   globalias () {
161         local MATCH
162         matched_chars='[.-|_a-zA-Z0-9]#'
163         LBUFFER=${LBUFFER%%(#m)[.-|_a-zA-Z0-9]#}
164         LBUFFER+=${abk[$MATCH]:-$MATCH}
165   }
166   zle -N globalias
167   bindkey ",." globalias
168 # }}}
169
170 ## another approach for global aliases: cloning vim's abbreviation feature {{{
171 # http://zshwiki.org/home/examples/zleiab
172 # typeset -A abbreviations
173 # abbreviations=(
174 #   "Im"    "| more"
175 #   "Ia"    "| awk"
176 #   "Ig"    "| grep"
177 #   "Ieg"   "| egrep"
178 #   "Iag"   "| agrep"
179 #   "Igr"   "| groff -s -p -t -e -Tlatin1 -mandoc"
180 #   "Ip"    "| $PAGER"
181 #   "Ih"    "| head"
182 #   "Ik"    "| keep"
183 #   "It"    "| tail"
184 #   "Is"    "| sort"
185 #   "Iv"    "| ${VISUAL:-${EDITOR}}"
186 #   "Iw"    "| wc"
187 #   "Ix"    "| xargs"
188 # )
189
190 # magic-abbrev-expand() {
191 #     local MATCH
192 #     LBUFFER=${LBUFFER%%(#m)[_a-zA-Z0-9]#}
193 #     LBUFFER+=${abbreviations[$MATCH]:-$MATCH}
194 #     zle self-insert
195 # }
196
197 # no-magic-abbrev-expand() {
198 #   LBUFFER+=' '
199 # }
200
201 # zle -N magic-abbrev-expand
202 # zle -N no-magic-abbrev-expand
203 # bindkey " " magic-abbrev-expand
204 # bindkey "^x " no-magic-abbrev-expand
205 # }}}
206
207 ## aliases {{{
208
209 # Xterm resizing-fu.
210 # Based on http://svn.kitenet.net/trunk/home-full/.zshrc?rev=11710&view=log (by Joey Hess)
211   alias hide='echo -en "\033]50;nil2\007"'
212   alias tiny='echo -en "\033]50;-misc-fixed-medium-r-normal-*-*-80-*-*-c-*-iso8859-15\007"'
213   alias small='echo -en "\033]50;6x10\007"'
214   alias medium='echo -en "\033]50;-misc-fixed-medium-r-normal--13-120-75-75-c-80-iso8859-15\007"'
215   alias default='echo -e "\033]50;-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-15\007"'
216   alias large='echo -en "\033]50;-misc-fixed-medium-r-normal-*-*-150-*-*-c-*-iso8859-15\007"'
217   alias huge='echo -en "\033]50;-misc-fixed-medium-r-normal-*-*-210-*-*-c-*-iso8859-15\007"'
218   alias smartfont='echo -en "\033]50;-artwiz-smoothansi-*-*-*-*-*-*-*-*-*-*-*-*\007"'
219   alias semifont='echo -en "\033]50;-misc-fixed-medium-r-semicondensed-*-*-120-*-*-*-*-iso8859-15\007"'
220 #  if [ "$TERM" = "xterm" ] && [ "$LINES" -ge 50 ] && [ "$COLUMNS" -ge 100 ] && [ -z "$SSH_CONNECTION" ]; then
221 #          large
222 #  fi
223
224 # general
225   alias da='du -sch'
226   alias j='jobs -l'
227 #  alias u='translate -i'          # translate
228
229 # compile stuff
230   alias CO="./configure"
231   alias CH="./configure --help"
232
233 # http://conkeror.mozdev.org/
234   alias conkeror='firefox -chrome chrome://conkeror/content'
235
236 # arch/tla stuff
237   alias ldiff='tla what-changed --diffs | less'
238   alias tbp='tla-buildpackage'
239   alias mirror='tla archive-mirror'
240   alias commit='tla commit'
241   alias merge='tla star-merge'
242
243 # listing stuff
244   alias dir="ls -lSrah"
245   alias lad='ls -d .*(/)'                # only show dot-directories
246   alias lsa='ls -a .*(.)'                # only show dot-files
247   alias lss='ls -l *(s,S,t)'             # only files with setgid/setuid/sticky flag
248   alias lsl='ls -l *(@[1,10])'           # only symlinks
249   alias lsx='ls -l *(*[1,10])'           # only executables
250   alias lsw='ls -ld *(R,W,X.^ND/)'       # world-{readable,writable,executable} files
251   alias lsbig="ls -flh *(.OL[1,10])"     # display the biggest files
252   alias lsd='ls -d *(/)'                 # only show directories
253   alias lse='ls -d *(/^F)'               # only show empty directories
254   alias lsnew="ls -rl *(D.om[1,10])"     # display the newest files
255   alias lsold="ls -rtlh *(D.om[1,10])"   # display the oldest files
256   alias lssmall="ls -Srl *(.oL[1,10])"   # display the smallest files
257
258 # chmod
259   alias rw-='chmod 600'
260   alias rwx='chmod 700'
261   alias r--='chmod 644'
262   alias r-x='chmod 755'
263
264 # some useful aliases
265   alias md='mkdir -p'
266
267 # console stuff
268   alias cmplayer='mplayer -vo fbdev'
269 #  alias fbmplayer='mplayer -vo fbdev'
270   alias fbmplayer='mplayer -vo fbdev -fs -zoom'
271   alias fblinks='links2 -driver fb'
272
273 # ignore ~/.ssh/known_hosts entries
274 #  alias insecssh='ssh -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=/dev/null" -o "PreferredAuthentications=keyboard-interactive"'
275   alias insecssh='ssh -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=/dev/null"'
276
277 # use colors when browsing man pages (if not using pinfo or PAGER=most)
278   [ -d ~/.terminfo/ ] && alias man='TERMINFO=~/.terminfo/ LESS=C TERM=mostlike PAGER=less man'
279
280 # check whether Debian's package management (dpkg) is running
281   alias check_dpkg_running="$SUDO dpkg_running"
282 # }}}
283
284 ## useful functions {{{
285
286 # functions without detailed explanation:
287   agoogle() { ${=BROWSER} "http://groups.google.com/groups?as_uauthors=$*" ; }
288   bk()      { cp -b ${1} ${1}_`date --iso-8601=m` }
289   cdiff()   { diff -crd "$*" | egrep -v "^Only in |^Binary files " }
290   cl()      { cd $1 && ls -a }        # cd && ls
291   cvsa()    { cvs add $* && cvs com -m 'initial checkin' $* }
292   cvsd()    { cvs diff -N $* |& $PAGER }
293   cvsl()    { cvs log $* |& $PAGER }
294   cvsq()    { cvs -nq update }
295   cvsr()    { rcs2log $* | $PAGER }
296   cvss()    { cvs status -v $* }
297   debbug()  { ${=BROWSER} "http://bugs.debian.org/$*" }
298   debbugm() { bts show --mbox $1 } # provide bugnummer as $1
299   disassemble(){ gcc -pipe -S -o - -O -g $* | as -aldh -o /dev/null }
300   dmoz()    { ${=BROWSER} http://search.dmoz.org/cgi-bin/search\?search=${1// /_} }
301   dwicti()  { ${=BROWSER} http://de.wiktionary.org/wiki/${(C)1// /_} }
302   ewicti()  { ${=BROWSER} http://en.wiktionary.org/wiki/${(C)1// /_} }
303   fir()     { firefox -a firefox -remote "openURL($1)" }
304   ggogle()  { ${=BROWSER} "http://groups.google.com/groups?q=$*" }
305   google()  { ${=BROWSER} "http://www.google.com/search?&num=100&q=$*" }
306   mdiff()   { diff -udrP "$1" "$2" > diff.`date "+%Y-%m-%d"`."$1" }
307   memusage(){ ps aux | awk '{if (NR > 1) print $5; if (NR > 2) print "+"} END { print "p" }' | dc }
308   mggogle() { ${=BROWSER} "http://groups.google.com/groups?selm=$*" }
309   netcraft(){ ${=BROWSER} "http://toolbar.netcraft.com/site_report?url=$1" }
310   oleo()    { ${=BROWSER} "http://dict.leo.org/?search=$*" }
311   shtar()   { gunzip -c $1 | tar -tf - -- | $PAGER }
312   shtgz()   { tar -ztf $1 | $PAGER }
313   shzip()   { unzip -l $1 | $PAGER }
314   sig()     { agrep -d '^-- $' "$*" ~/.Signature }
315   swiki()   { ${=BROWSER} http://de.wikipedia.org/wiki/Spezial:Search/${(C)1} }
316   udiff()   { diff -urd $* | egrep -v "^Only in |^Binary files " }
317   viless()  { vim --cmd 'let no_plugin_maps = 1' -c "so \$VIMRUNTIME/macros/less.vim" "${@:--}" }
318   wikide () { ${=BROWSER} http://de.wikipedia.org/wiki/"${(C)*}" }
319   wikien()  { ${=BROWSER} http://en.wikipedia.org/wiki/"$*" }
320   wodeb ()  { ${=BROWSER} "http://packages.debian.org/cgi-bin/search_contents.pl?word=$1&version=${2:-unstable}" }
321
322   which google >/dev/null 2>&1 && gex () { google "\"[ $1]\" $*" } # exact search at google
323
324 # Function Usage: doc packagename
325   doc() { cd /usr/share/doc/$1 && ls }
326   _doc() { _files -W /usr/share/doc -/ }
327   compdef _doc doc
328
329 # debian upgrade
330   upgrade () {
331     if [ -z $1 ] ; then
332         $SUDO apt-get update
333         $SUDO apt-get -u upgrade
334     else
335         ssh $1 $SUDO apt-get update
336         # ask before the upgrade
337         local dummy
338         ssh $1 $SUDO apt-get --no-act upgrade
339         echo -n "Process the upgrade ?"
340         read -q dummy
341         if [[ $dummy == "y" ]] ; then
342             ssh $1 $SUDO apt-get -u upgrade --yes
343         fi
344     fi
345   }
346
347 # make screenshot of current desktop (use 'import' from ImageMagic)
348   sshot() {
349         [[ ! -d ~/shots  ]] && mkdir ~/shots
350         #cd ~/shots ; sleep 5 ; import -window root -depth 8 -quality 80 `date "+%Y-%m-%d--%H:%M:%S"`.png
351         cd ~/shots ; sleep 5; import -window root shot_`date --iso-8601=m`.jpg
352   }
353
354
355 # list images only
356   limg() {
357     local -a images
358     images=( *.{jpg,gif,png}(.N) )
359     if [[ $#images -eq 0 ]] ; then
360       print "No image files found"
361     else
362       ls "$@" "$images[@]"
363     fi
364   }
365
366
367 # create pdf file from source code
368   makereadable() {
369      output=$1
370      shift
371      a2ps --medium A4dj -E -o $output $*
372      ps2pdf $output
373   }
374
375 # zsh with perl-regex - use it e.g. via:
376 # regcheck '\s\d\.\d{3}\.\d{3} Euro' ' 1.000.000 Euro'
377   regcheck() {
378     zmodload -i zsh/pcre
379     pcre_compile $1 && \
380     pcre_match $2 && echo "regex matches" || echo "regex does not match"
381   }
382 # list files which have been modified within the last x days
383   new() { print -l *(m-$1) }
384
385 # grep the history
386   greph () { history 0 | grep $1 }
387   (grep --help 2>/dev/null |grep -- --color) >/dev/null && \
388     alias grep='grep --color=auto' # use colors when GNU grep with color-support
389   alias GREP='grep -i --color=auto'
390
391 # one blank line between each line
392   if [ -r ~/.terminfo/m/mostlike ] ; then
393 #     alias man2='MANPAGER="sed -e G |less" TERMINFO=~/.terminfo TERM=mostlike /usr/bin/man'
394      man2() { PAGER='dash -c "sed G | /usr/bin/less"' TERM=mostlike /usr/bin/man "$@" ; }
395   fi
396
397 # jump between directories
398 # Copyright 2005 Nikolai Weibull <nikolai@bitwi.se>
399 # notice: option AUTO_PUSHD has to be set
400   d(){
401     emulate -L zsh
402     autoload -U colors
403     local color=$fg_bold[blue]
404     integer i=0
405     dirs -p | while read dir; do
406       local num="${$(printf "%-4d " $i)/ /.}"
407       printf " %s  $color%s$reset_color\n" $num $dir
408       (( i++ ))
409     done
410     integer dir=-1
411     read -r 'dir?Jump to directory: ' || return
412     (( dir == -1 )) && return
413     if (( dir < 0 || dir >= i )); then
414       echo d: no such directory stack entry: $dir
415       return 1
416     fi
417     cd ~$dir
418   }
419
420 # provide useful information on globbing
421   H-Glob() {
422   echo -e "
423       /      directories
424       .      plain files
425       @      symbolic links
426       =      sockets
427       p      named pipes (FIFOs)
428       *      executable plain files (0100)
429       %      device files (character or block special)
430       %b     block special files
431       %c     character special files
432       r      owner-readable files (0400)
433       w      owner-writable files (0200)
434       x      owner-executable files (0100)
435       A      group-readable files (0040)
436       I      group-writable files (0020)
437       E      group-executable files (0010)
438       R      world-readable files (0004)
439       W      world-writable files (0002)
440       X      world-executable files (0001)
441       s      setuid files (04000)
442       S      setgid files (02000)
443       t      files with the sticky bit (01000)
444    print *(m-1)          # Dateien, die vor bis zu einem Tag modifiziert wurden.
445    print *(a1)           # Dateien, auf die vor einem Tag zugegriffen wurde.
446    print *(@)            # Nur Links
447    print *(Lk+50)        # Dateien die ueber 50 Kilobytes grosz sind
448    print *(Lk-50)        # Dateien die kleiner als 50 Kilobytes sind
449    print **/*.c          # Alle *.c - Dateien unterhalb von \$PWD
450    print **/*.c~file.c   # Alle *.c - Dateien, aber nicht 'file.c'
451    print (foo|bar).*     # Alle Dateien mit 'foo' und / oder 'bar' am Anfang
452    print *~*.*           # Nur Dateien ohne '.' in Namen
453    chmod 644 *(.^x)      # make all non-executable files publically readable
454    print -l *(.c|.h)     # Nur Dateien mit dem Suffix '.c' und / oder '.h'
455    print **/*(g:users:)  # Alle Dateien/Verzeichnisse der Gruppe >users<
456    echo /proc/*/cwd(:h:t:s/self//) # Analog zu >ps ax | awk '{print $1}'<"
457   }
458
459   lcheck() {
460    nm -go /usr/lib/lib*.a 2>/dev/null | grep ":[[:xdigit:]]\{8\} . .*$1"":[[:xdigit:]]\{8\} . .*$1"
461   }
462
463 # clean up directory
464   purge() {
465         FILES=(*~(N) .*~(N) \#*\#(N) *.o(N) a.out(N) *.core(N) *.cmo(N) *.cmi(N) .*.swp(N))
466         NBFILES=${#FILES}
467         if [[ $NBFILES > 0 ]]; then
468                 print $FILES
469                 local ans
470                 echo -n "Remove these files? [y/n] "
471                 read -q ans
472                 if [[ $ans == "y" ]]
473                 then
474                         rm ${FILES}
475                         echo ">> $PWD purged, $NBFILES files removed"
476                 else
477                         echo "Ok. .. than not.."
478                 fi
479         fi
480    }
481
482 # Translate DE<=>EN
483 # 'translate' looks up fot a word in a file with language-to-language
484 # translations (field separator should be " : "). A typical wordlist looks
485 # like at follows:
486 #  | english-word : german-transmission
487 # It's also only possible to translate english to german but not reciprocal.
488 # Use the following oneliner to turn back the sort order:
489 #  $ awk -F ':' '{ print $2" : "$1" "$3 }' \
490 #    /usr/local/lib/words/en-de.ISO-8859-1.vok > ~/.translate/de-en.ISO-8859-1.vok
491   trans() {
492         case "$1" in
493                 -[dD]*) translate -l de-en $2
494                 ;;
495                 -[eE]*) translate -l en-de $2
496                 ;;
497                 *)
498                 echo "Usage: $0 { -D | -E }"
499                 echo "         -D == German to English"
500                 echo "         -E == English to German"
501         esac
502   }
503
504 # Some quick Perl-hacks aka /useful/ oneliner
505 #  bew() { perl -le 'print unpack "B*","'$1'"' }
506 #  web() { perl -le 'print pack "B*","'$1'"' }
507 #  hew() { perl -le 'print unpack "H*","'$1'"' }
508 #  weh() { perl -le 'print pack "H*","'$1'"' }
509 #  pversion()    { perl -M$1 -le "print $1->VERSION" } # i. e."pversion LWP -> 5.79"
510 #  getlinks ()   { perl -ne 'while ( m/"((www|ftp|http):\/\/.*?)"/gc ) { print $1, "\n"; }' $* }
511 #  gethrefs ()   { perl -ne 'while ( m/href="([^"]*)"/gc ) { print $1, "\n"; }' $* }
512 #  getanames ()  { perl -ne 'while ( m/a name="([^"]*)"/gc ) { print $1, "\n"; }' $* }
513 #  getforms ()   { perl -ne 'while ( m:(\</?(input|form|select|option).*?\>):gic ) { print $1, "\n"; }' $* }
514 #  getstrings () { perl -ne 'while ( m/"(.*?)"/gc ) { print $1, "\n"; }' $*}
515 #  getanchors () { perl -ne 'while ( m/«([^«»\n]+)»/gc ) { print $1, "\n"; }' $* }
516 #  showINC ()    { perl -e 'for (@INC) { printf "%d %s\n", $i++, $_ }' }
517 #  vimpm ()      { vim `perldoc -l $1 | sed -e 's/pod$/pm/'` }
518 #  vimhelp ()    { vim -c "help $1" -c on -c "au! VimEnter *" }
519
520 # plap foo -- list all occurrences of program in the current PATH
521   plap() {
522         if [[ $# = 0 ]]
523         then
524                 echo "Usage:    $0 program"
525                 echo "Example:  $0 zsh"
526                 echo "Lists all occurrences of program in the current PATH."
527         else
528                 ls -l ${^path}/*$1*(*N)
529         fi
530   }
531
532 # Found in the mailinglistarchive from Zsh (IIRC ~1996)
533   selhist() {
534         emulate -L zsh
535         local TAB=$'\t';
536         (( $# < 1 )) && {
537                 echo "Usage: $0 command"
538                 return 1
539         };
540         cmd=(${(f)"$(grep -w $1 $HISTFILE | sort | uniq | pr -tn)"})
541         print -l $cmd | less -F
542         echo -n "enter number of desired command [1 - $(( ${#cmd[@]} - 1 ))]: "
543         local answer
544         read answer
545         print -z "${cmd[$answer]#*$TAB}"
546   }
547
548 # mkdir && cd
549   mcd() { mkdir -p "$@"; cd "$@" }  # mkdir && cd
550
551 # cd && ls
552   cl() { cd $1 && ls -a }
553
554 # Use vim to convert plaintext to HTML
555   2html() { vim -u NONE -n -c ':syntax on' -c ':so $VIMRUNTIME/syntax/2html.vim' -c ':wqa' $1 > /dev/null 2> /dev/null }
556
557 # Usage: simple-extract <file>
558 # Description: extracts archived files (maybe)
559   simple-extract () {
560         if [[ -f $1 ]]
561         then
562                 case $1 in
563                         *.tar.bz2)  bzip2 -v -d $1      ;;
564                         *.tar.gz)   tar -xvzf $1        ;;
565                         *.rar)      unrar $1            ;;
566                         *.deb)      ar -x $1            ;;
567                         *.bz2)      bzip2 -d $1         ;;
568                         *.lzh)      lha x $1            ;;
569                         *.gz)       gunzip -d $1        ;;
570                         *.tar)      tar -xvf $1         ;;
571                         *.tgz)      gunzip -d $1        ;;
572                         *.tbz2)     tar -jxvf $1        ;;
573                         *.zip)      unzip $1            ;;
574                         *.Z)        uncompress $1       ;;
575                         *)          echo "'$1' Error. Please go away" ;;
576                 esac
577         else
578                 echo "'$1' is not a valid file"
579         fi
580   }
581
582 # Usage: smartcompress <file> (<type>)
583 # Description: compresses files or a directory.  Defaults to tar.gz
584   smartcompress() {
585         if [ $2 ]; then
586                 case $2 in
587                         tgz | tar.gz)   tar -zcvf$1.$2 $1 ;;
588                         tbz2 | tar.bz2) tar -jcvf$1.$2 $1 ;;
589                         tar.Z)          tar -Zcvf$1.$2 $1 ;;
590                         tar)            tar -cvf$1.$2  $1 ;;
591                         gz | gzip)      gzip           $1 ;;
592                         bz2 | bzip2)    bzip2          $1 ;;
593                         *)
594                         echo "Error: $2 is not a valid compression type"
595                         ;;
596                 esac
597         else
598                 smartcompress $1 tar.gz
599         fi
600   }
601
602 # Usage: show-archive <archive>
603 # Description: view archive without unpack
604   show-archive() {
605         if [[ -f $1 ]]
606         then
607                 case $1 in
608                         *.tar.gz)      gunzip -c $1 | tar -tf - -- ;;
609                         *.tar)         tar -tf $1 ;;
610                         *.tgz)         tar -ztf $1 ;;
611                         *.zip)         unzip -l $1 ;;
612                         *.bz2)         bzless $1 ;;
613                         *)             echo "'$1' Error. Please go away" ;;
614                 esac
615         else
616                 echo "'$1' is not a valid archive"
617         fi
618   }
619
620   folsym() {
621     if [[ -e $1 || -h $1 ]]; then
622         file=$1
623     else
624         file=`which $1`
625     fi
626     if [[ -e $file || -L $file ]]; then
627         if [[ -L $file ]]; then
628             echo `ls -ld $file | perl -ane 'print $F[7]'` '->'
629             folsym `perl -le '$file = $ARGV[0];
630                               $dest = readlink $file;
631                               if ($dest !~ m{^/}) {
632                                   $file =~ s{(/?)[^/]*$}{$1$dest};
633                               } else {
634                                   $file = $dest;
635                               }
636                               $file =~ s{/{2,}}{/}g;
637                               while ($file =~ s{[^/]+/\.\./}{}) {
638                                   ;
639                               }
640                               $file =~ s{^(/\.\.)+}{};
641                               print $file' $file`
642         else
643             ls -d $file
644         fi
645     else
646         echo $file
647     fi
648   }
649
650 # Use 'view' to read manpages, if u want colors, regex - search, ...
651 # like vi(m).
652 # It's shameless stolen from <http://www.vim.org/tips/tip.php?tip_id=167>
653   vman() { man $* | col -b | view -c 'set ft=man nomod nolist' - }
654
655 # search for various types or README file in dir and display them in $PAGER
656 # function readme() { $PAGER -- (#ia3)readme* }
657   readme() {
658         local files
659         files=(./(#i)*(read*me|lue*m(in|)ut)*(ND))
660         if (($#files))
661         then $PAGER $files
662         else
663                 print 'No README files.'
664         fi
665   }
666
667 # find all suid files in $PATH
668 # suidfind() { ls -latg $path | grep '^...s' }
669   suidfind() { ls -latg $path/*(sN) }
670
671 # See above but this is /better/ ... anywise ..
672   findsuid() {
673     print 'Output will be written to ~/suid_* ...'
674     $SUDO find / -type f \( -perm -4000 -o -perm -2000 \) -ls > ~/suid_suidfiles.`date "+%Y-%m-%d"`.out 2>&1
675     $SUDO find / -type d \( -perm -4000 -o -perm -2000 \) -ls > ~/suid_suiddirs.`date "+%Y-%m-%d"`.out 2>&1
676     $SUDO find / -type f \( -perm -2 -o -perm -20 \) -ls > ~/suid_writefiles.`date "+%Y-%m-%d"`.out 2>&1
677     $SUDO find / -type d \( -perm -2 -o -perm -20 \) -ls > ~/suid_writedirs.`date "+%Y-%m-%d"`.out 2>&1
678     print 'Finished'
679   }
680
681 # Reload functions.
682   refunc() {
683         for func in $argv
684         do
685                 unfunction $func
686                 autoload $func
687         done
688   }
689
690 # a small check to see which DIR is located on which server/partition.
691 # stolen and modified from Sven's zshrc.forall
692   dirspace() {
693         for dir in $path;
694         do
695                 (cd $dir; echo "-<$dir>"; du -shx .; echo);
696         done
697   }
698
699 # $ show_print `cat /etc/passwd`
700   slow_print() {
701         for argument in "${@}"
702         do
703                 for ((i = 1; i <= ${#1} ;i++)) {
704                         print -n "${argument[i]}"
705                         sleep 0.08
706                 }
707                 print -n " "
708         done
709         print ""
710   }
711
712   status() {
713         print ""
714         print "Date..: "$(date "+%Y-%m-%d %H:%M:%S")""
715         print "Shell.: Zsh $ZSH_VERSION (PID = $$, $SHLVL nests)"
716         print "Term..: $TTY ($TERM), $BAUD bauds, $COLUMNS x $LINES cars"
717         print "Login.: $LOGNAME (UID = $EUID) on $HOST"
718         print "System: $(cat /etc/[A-Za-z]*[_-][rv]e[lr]*)"
719         print "Uptime:$(uptime)"
720         print ""
721   }
722
723   audiorip() {
724         mkdir -p ~/ripps
725         cd ~/ripps
726         cdrdao read-cd --device $DEVICE --driver generic-mmc audiocd.toc
727         cdrdao read-cddb --device $DEVICE --driver generic-mmc audiocd.toc
728         echo " * Would you like to burn the cd now? (yes/no)"
729         read input
730         if
731                 [ "$input" = "yes" ]; then
732                 echo " ! Burning Audio CD"
733                 audioburn
734                 echo " * done."
735         else
736                 echo " ! Invalid response."
737         fi
738   }
739
740   audioburn() {
741         cd ~/ripps
742         cdrdao write --device $DEVICE --driver generic-mmc audiocd.toc
743         echo " * Should I remove the temporary files? (yes/no)"
744         read input
745         if [ "$input" = "yes" ]; then
746                 echo " ! Removing Temporary Files."
747                 cd ~
748                 rm -rf ~/ripps
749                 echo " * done."
750         else
751                 echo " ! Invalid response."
752         fi
753   }
754
755   mkaudiocd() {
756         cd ~/ripps
757         for i in *.[Mm][Pp]3; do mv "$i" `echo $i | tr '[A-Z]' '[a-z]'`; done
758         for i in *.mp3; do mv "$i" `echo $i | tr ' ' '_'`; done
759         for i in *.mp3; do mpg123 -w `basename $i .mp3`.wav $i; done
760         normalize -m *.wav
761         for i in *.wav; do sox $i.wav -r 44100 $i.wav resample; done
762   }
763
764   mkiso() {
765         echo " * Volume name "
766         read volume
767         echo " * ISO Name (ie. tmp.iso)"
768         read iso
769         echo " * Directory or File"
770         read files
771         mkisofs -o ~/$iso -A $volume -allow-multidot -J -R -iso-level 3 -V $volume -R $files
772   }
773
774 # generate thumbnails ;)
775   genthumbs () {
776     rm -rf thumb-* index.html
777     echo "
778 <html>
779   <head>
780     <title>Images</title>
781   </head>
782   <body>" > index.html
783     for f in *.(gif|jpeg|jpg|png)
784     do
785         convert -size 100x200 "$f" -resize 100x200 thumb-"$f"
786         echo "    <a href=\"$f\"><img src=\"thumb-$f\"></a>" >> index.html
787     done
788     echo "
789   </body>
790 </html>" >> index.html
791   }
792
793 # unset all limits (see zshbuiltins(1) /ulimit for details)
794   allulimit() {
795     ulimit -c unlimited
796     ulimit -d unlimited
797     ulimit -f unlimited
798     ulimit -l unlimited
799     ulimit -n unlimited
800     ulimit -s unlimited
801     ulimit -t unlimited
802   }
803
804 # ogg2mp3 with bitrate of 192
805   ogg2mp3_192() {
806     oggdec -o - ${1} | lame -b 192 - ${1:r}.mp3
807   }
808
809 # RFC 2396 URL encoding in Z-Shell
810   urlencode() {
811    setopt localoptions extendedglob
812    input=( ${(s::)1} )
813    print ${(j::)input/(#b)([^A-Za-z0-9_.!~*\'\(\)-])/%$(([##16]#match))}
814   }
815
816 # get x-lite voip software
817   getxlite() {
818     setopt local_options
819     setopt errreturn
820     [ -d ~/tmp ] || mkdir ~/tmp
821     cd ~/tmp
822     echo "Downloading http://www.counterpath.com/download/X-Lite_Install.tar.gz and storing it in ~/tmp:"
823     if wget http://www.counterpath.com/download/X-Lite_Install.tar.gz ; then
824        unp X-Lite_Install.tar.gz && echo done || echo failed
825     else
826        echo "Error while downloading." ; return 1
827     fi
828     if [ -x xten-xlite/xtensoftphone ] ; then
829        echo "Execute xten-xlite/xtensoftphone to start xlite."
830     fi
831    }
832
833 # get skype
834   getskype() {
835     setopt local_options
836     setopt errreturn
837     echo "Downloading debian package of skype."
838     echo "Notice: If you want to use a more recent skype version run 'getskypebeta'."
839     wget http://www.skype.com/go/getskype-linux-deb
840     $SUDO dpkg -i skype_debian-*.deb && echo "skype installed."
841   }
842
843 # get beta-version of skype
844   getskypebeta() {
845     setopt local_options
846     setopt errreturn
847     echo "Downloading debian package of skype (beta version)."
848     wget http://www.skype.com/go/getskype-linux-beta-deb
849     $SUDO dpkg -i skype-beta*.deb && echo "skype installed."
850   }
851
852 # get gzimo (voicp software)
853   getgizmo() {
854     setopt local_options
855     setopt errreturn
856     echo "gconf2-common and libgconf2-4 have to be available. Installing therefor."
857     $SUDO apt-get update
858     $SUDO apt-get install gconf2-common libgconf2-4
859     wget $(lynx --dump http://www.gizmoproject.com/download-linux.html | awk '/\.deb/ {print $2" "}' | tr -d '\n')
860     $SUDO dpkg -i libsipphoneapi*.deb bonjour_*.deb gizmo-*.deb && echo "gizmo installed."
861   }
862
863 # get AIR - Automated Image and Restore
864   getair() {
865     setopt local_options
866     setopt errreturn
867     [ -w . ] || { echo 'Error: you do not have write permissions in this directory. Exiting.' ; return 1 }
868     local VER='1.2.8'
869     wget http://puzzle.dl.sourceforge.net/sourceforge/air-imager/air-$VER.tar.gz
870     tar zxf air-$VER.tar.gz
871     cd air-$VER
872     INTERACTIVE=no $SUDO ./install-air-1.2.8
873     [ -x /usr/local/bin/air ] && [ -n "$DISPLAY" ] && $SUDO air
874   }
875
876 # get specific git commitdiff
877   git-get-diff() {
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=commitdiff;h=$1"
883     else
884       echo "Usage: git-get-diff <commit>"
885     fi
886   }
887
888 # get specific git commit
889   git-get-commit() {
890     if [ -z $GITTREE ] ; then
891       GITTREE='linux/kernel/git/torvalds/linux-2.6.git'
892     fi
893     if ! [ -z $1 ] ; then
894      ${=BROWSER} "http://kernel.org/git/?p=$GITTREE;a=commit;h=$1"
895     else
896       echo "Usage: git-get-commit <commit>"
897     fi
898   }
899
900 # get specific git diff
901   git-get-plaindiff() {
902     if [ -z $GITTREE ] ; then
903       GITTREE='linux/kernel/git/torvalds/linux-2.6.git'
904     fi
905     if ! [ -z $1 ] ; then
906       wget "http://kernel.org/git/?p=$GITTREE;a=commitdiff_plain;h=$1" -O $1.diff
907     else
908       echo 'Usage: git-get-plaindiff '
909     fi
910   }
911
912 # log 'make install' output
913 # http://strcat.de/blog/index.php?/archives/335-Software-sauber-deinstallieren...html
914   mmake() {
915     [[ ! -d ~/.errorlogs ]] && mkdir ~/.errorlogs
916     =make -n install > ~/.errorlogs/${PWD##*/}-makelog
917   }
918
919 # indent source code
920   smart-indent() {
921     indent -npro -kr -i8 -ts8 -sob -l80 -ss -ncs $*
922   }
923
924 # highlight important stuff in diff output, usage example: hg diff | hidiff
925   [ -x =histring ] && \
926   alias hidiff="histring -fE '^Comparing files .*|^diff .*' | histring -c yellow -fE '^\-.*' | histring -c green -fE '^\+.*'"
927
928 # rename pictures based on information found in exif headers
929   exirename() {
930     if [ $# -lt 1 ] ; then
931        echo 'Usage: jpgrename $FILES' >& 2
932        return 1
933     else
934        echo -n 'Checking for jhead with version newer than 1.9: '
935        jhead_version=`jhead -h | grep 'used by most Digital Cameras.  v.*' | awk '{print $6}' | tr -d v`
936        if [[ $jhead_version > '1.9' ]]; then
937           echo 'success - now running jhead.'
938           jhead -n%Y-%m-%d_%Hh%M_%f $*
939        else
940           echo 'failed - exiting.'
941        fi
942     fi
943   }
944 # }}}
945
946 # mercurial related stuff {{{
947   if type -p hg >/dev/null 2>&1 ; then
948   # gnu like diff for mercurial
949   # http://www.selenic.com/mercurial/wiki/index.cgi/TipsAndTricks
950     hgdi() {
951       for i in `hg status -marn "$@"` ; diff -ubwd <(hg cat "$i") "$i"
952     }
953
954   # diffstat for specific version of mercurial
955   #   hgstat      => display diffstat between last revision and tip
956   #   hgstat 1234 => display diffstat between revision 1234 and tip
957     hgstat() {
958       [ -n "$1" ] && hg diff -r $1 -r tip | diffstat || hg export tip | diffstat
959     }
960
961   # get current mercurial tip via hg itself and install it in $HOME
962   gethgclone() {
963     setopt local_options
964     setopt errreturn
965     if [ -f mercurial-tree/.hg ] ; then
966       cd mercurial-tree
967       echo "Running hg pull for retreiving latest version..."
968       hg pull
969       echo "Finished update. Building mercurial"
970       make local
971       echo "Setting \$PATH to $PWD:\$PATH..."
972       export PATH="$PWD:$PATH"
973     else
974       echo "Downloading mercurial via hg"
975       hg clone http://selenic.com/repo/hg mercurial-tree
976       cd mercurial-tree
977       echo "Building mercurial"
978       make local
979       echo "Setting \$PATH to $PWD:\$PATH..."
980       export PATH="$PWD:$PATH"
981       echo "make sure you set it permanent via ~/.zshrc if you plan to use it permanently."
982       # echo "Setting \$PYTHONPATH to PYTHONPATH=\${HOME}/lib/python,"
983       # export PYTHONPATH=${HOME}/lib/python
984     fi
985   }
986
987   fi # end of check whether we have the 'hg'-executable
988
989   # get and install current mercurial snapshot in $HOME
990   gethgsnap() {
991     setopt local_options
992     setopt errreturn
993     if [ -f mercurial-snapshot.tar.gz ] ; then
994        echo "mercurial-snapshot.tar.gz exists already, skipping download."
995     else
996       echo "Downloading mercurial snapshot"
997       wget http://www.selenic.com/mercurial/mercurial-snapshot.tar.gz
998     fi
999     echo "Unpacking mercurial-snapshot.tar.gz"
1000     tar zxf mercurial-snapshot.tar.gz
1001     cd mercurial-snapshot/
1002     echo "Installing required build-dependencies"
1003     $SUDO apt-get update
1004     $SUDO apt-get install python2.4-dev
1005     echo "Building mercurial"
1006     make local
1007     echo "Setting \$PATH to $PWD:\$PATH..."
1008     export PATH="$PWD:$PATH"
1009     echo "make sure you set it permanent via ~/.zshrc if you plan to use it permanently."
1010   }
1011 # }}}
1012
1013 # some useful commands often hard to remember - let's grep for them {{{
1014
1015 # Work around ion/xterm resize bug.
1016 #if [ "$SHLVL" = 1 ]; then
1017 #       if [ -x `which resize 2>/dev/null` ]; then
1018 #               eval `resize </dev/null`
1019 #       fi
1020 #fi
1021
1022 # enable jackd:
1023 #  /usr/bin/jackd -dalsa -dhw:0 -r48000 -p1024 -n2
1024 # now play audio file:
1025 #  alsaplayer -o jack foobar.mp3
1026
1027 # send files via netcat
1028 # on sending side:
1029 #  send() {j=$*; tar cpz ${j/%${!#}/}|nc -w 1 ${!#} 51330;}
1030 #  send dir* $HOST
1031 #  alias receive='nc -vlp 51330 | tar xzvp'
1032
1033 # debian stuff:
1034 # dh_make -e foo@localhost -f $1
1035 # dpkg-buildpackage -rfakeroot
1036 # lintian *.deb
1037 # dpkg-scanpackages ./ /dev/null | gzip > Packages.gz
1038 # dpkg-scansources . | gzip > Sources.gz
1039 # grep-dctrl --field Maintainer $* /var/lib/apt/lists/*
1040
1041 # other stuff:
1042 # convert -geometry 200x200 -interlace LINE -verbose
1043 # ldapsearch -x -b "OU=Bedienstete,O=tug" -h ldap.tugraz.at sn=$1
1044 # ps -ao user,pcpu,start,command
1045 # gpg --keyserver blackhole.pca.dfn.de --recv-keys
1046 # xterm -bg black -fg yellow -fn -misc-fixed-medium-r-normal--14-140-75-75-c-90-iso8859-15 -ah
1047 # nc -vz $1 1-1024   # portscan via netcat
1048 # wget --mirror --no-parent --convert-links
1049 # pal -d `date +%d`
1050 # autoload -U tetris; zle -N tetris; bindkey '...' ; echo "press ... for playing tennis"
1051 #
1052 # modify console cursor
1053 # see http://www.tldp.org/HOWTO/Framebuffer-HOWTO-5.html
1054 # print $'\e[?96;0;64c'
1055 # }}}
1056
1057 # finally source a local zshrc {{{
1058 # this allows us to stay in sync with /etc/skel/.zshrc
1059 # through 'ln -s /etc/skel/.zshrc ~/.zshrc' and put own
1060 # modifications in ~/.zshrc.local
1061   if [ -r ~/.zshrc.local ] ; then
1062      . ~/.zshrc.local
1063   fi
1064 # }}}
1065
1066 ## END OF FILE #################################################################
1067 # vim:foldmethod=marker