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