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