initial checkin
[zsh-lovers.git] / zsh_people / strcat / zshfunctions
1 # Globbing is simple? Sure .. See zshexpn(1) /Glob Qualifiers for details and
2 # come back ;) 
3 function H-Glob()
4 {
5 echo -e "
6      /      directories
7       .      plain files
8       @      symbolic links
9       =      sockets
10       p      named pipes (FIFOs)
11       *      executable plain files (0100)
12       %      device files (character or block special)
13       %b     block special files
14       %c     character special files
15       r      owner-readable files (0400)
16       w      owner-writable files (0200)
17       x      owner-executable files (0100)
18       A      group-readable files (0040)
19       I      group-writable files (0020)
20       E      group-executable files (0010)
21       R      world-readable files (0004)
22       W      world-writable files (0002)
23       X      world-executable files (0001)
24       s      setuid files (04000)
25       S      setgid files (02000)
26       t      files with the sticky bit (01000)
27  print *(m-1)          # Dateien, die vor bis zu einem Tag modifiziert wurden.
28  print *(a1)           # Dateien, auf die vor einem Tag zugegriffen wurde.
29  print *(@)            # Nur Links
30  print *(Lk+50)        # Dateien die ueber 50 Kilobytes grosz sind
31  print *(Lk-50)        # Dateien die kleiner als 50 Kilobytes sind
32  print **/*.c          # Alle *.c - Dateien unterhalb von \$PWD
33  print **/*.c~file.c   # Alle *.c - Dateien, aber nicht 'file.c'
34  print (foo|bar).*     # Alle Dateien mit 'foo' und / oder 'bar' am Anfang
35  print *~*.*           # Nur Dateien ohne '.' in Namen
36  chmod 644 *(.^x)      # make all non-executable files publically readable
37  print -l *(.c|.h)     # Nur Dateien mit dem Suffix '.c' und / oder '.h'
38  print **/*(g:users:)  # Alle Dateien/Verzeichnisse der Gruppe >users<
39  echo /proc/*/cwd(:h:t:s/self//) # Analog zu >ps ax | awk '{print $1}'<"
40 }
41
42 # colorizing the output of make
43 if [[ -x ~/bin/makefilter ]]
44 then
45         make() { command make "$@" |& makefilter }
46 fi
47
48 # check if ~/.errorlogs/ exist (otherwise create it) and create a
49 # ``logfile'' e. g. ``makelog-vim-6.3''
50 function mmake()
51 {
52         [[ ! -d ~/.errorlogs ]] && mkdir ~/.errorlogs
53         =make -n install > ~/.errorlogs/${PWD##*/}-makelog
54 }
55
56 # Search for the argument in the system libraries
57 function lcheck()
58 {
59         nm -go /usr/lib/lib*.a /usr/lobal/lib/lib*.a 2>/dev/null | grep ":[[:xdigit:]]\{8\} . .*$1"":[[:xdigit:]]\{8\} . .*$1"
60 }
61
62 # clean directory
63 function purge()
64 {
65         FILES=(*~(N) .*~(N) \#*\#(N) *.o(N) a.out(N) *.core(N) *.cmo(N) *.cmi(N) .*.swp(N))
66         NBFILES=${#FILES}
67         if [[ $NBFILES > 0 ]]; then
68                 print $FILES
69                 local ans
70                 echo -n "Remove this files? [y/n] "
71                 read -q ans
72                 if [[ $ans == "y" ]]
73                 then
74                         rm ${FILES}
75                         echo ">> $PWD purged, $NBFILES files removed"
76                 else
77                         echo "Ok. .. than not.."
78                 fi
79         fi
80 }
81
82 # display a of possible passwords.
83 function makepasswords()
84 {
85         perl <<EOPERL
86         my @a = ("a".."z","A".."Z","0".."9",(split //, q{#@,.<>$%&()*^}));
87         for (1..10) { 
88                 print join "", map { \$a[rand @a] } (1..rand(3)+7);
89                 print qq{\n} 
90         }
91 EOPERL
92 }
93 # AUTOMATIC ls on chpwd *if* directly isn't too big.
94 # Not really needed ;o)
95 #function chpwd
96 #{
97 #       integer ls_lines="$(ls -C | wc -l)"
98 #       if [ $ls_lines -eq 0 ]; then
99 #               echo No files found: Empty Directory 
100 #       elif [ $ls_lines -le 18 ]; then
101 #               ls
102 #               echo "\e[1;32m --[ Items: `ls -l | wc -l` \e[1;32m]--"
103 #       else
104 #               echo Directory Exceeds Limits.
105 #       fi
106 #}
107
108 # ssh-add -- wrap ssh-add to default to adding all identities in
109 # ${HOME}/.ssh
110 function ssh-add()
111 {
112         local files
113         if [[ $# -eq 0 ]] ; then
114                 for i in id_dsa id_rsa identity ; do
115                         if [[ -f $HOME/.ssh/$i ]] ; then
116                                 files=($files $HOME/.ssh/$i)
117                         fi
118                 done
119         else
120                 files=( "$@" )
121         fi
122         command ssh-add $files
123 }
124
125 # Name (``hash -d'') all the subdirectories in given directory
126 # $ mkdir -p foo/{bar,foo,fnord,recursion}
127 # $ quick-hash foo
128 # $ hash -d
129 # bar=foo/bar
130 # fnord=foo/fnord
131 # foo=foo/foo
132 # recursion=foo/recursion
133 function quick-hash()
134 {
135         for i in $1/*(/)
136         do
137                 hash -d ${i##*/}=$i
138         done
139 }
140
141 # print current settings of LC_*
142 function plocale()
143 {
144         print LC_ALL=$LC_ALL
145         print LANG=$LANG
146         print LC_CTYPE=$LC_CTYPE
147         print LC_NUMERIC=$LC_NUMERIC
148         print LC_TIME=$LC_TIME
149         print LC_COLLATE=$LC_COLLATE
150         print LC_MONETARY=$LC_MONETARY
151         print LC_MESSAGES=$LC_MESSAGES
152         print LC_PAPER=$LC_PAPER
153         print LC_NAME=$LC_NAME
154         print LC_ADDRESS=$LC_ADDRESS
155         print LC_TELEPHONE=$LC_TELEPHONE
156         print LC_MEASUREMENT=$LC_MEASUREMENT
157         print LC_IDENTIFICATION=$LC_IDENTIFICATION
158 }
159 # a clock in the prompt. 
160 #trap CRON ALRM
161 #TMOUT=1
162 #CRON() {
163 #   local STRING
164 #   local COL
165 #   local x
166 #   STRING=$(date)
167 #   COL=$[COLUMNS-5]
168 #   COL=$[COL-$#STRING]
169 #   x=$(echo $PREBUFFER | wc -l )
170 #   x=$[x+1]
171 #   echo -n "\e7\e[$x;A\e[$COL;G\e[0;37;44m-- $STRING --\e[0m\e8"
172 #}
173
174 # invoke this every time when u change .zshrc to recompile it.
175 function src()
176 {
177         autoload -U zrecompile
178                 [ -f ~/.zshrc ] && zrecompile -p ~/.zshrc
179                 [ -f ~/.zcompdump ] && zrecompile -p ~/.zcompdump
180                 [ -f ~/.zcompdump ] && zrecompile -p ~/.zcompdump
181                 [ -f ~/.zshrc.zwc.old ] && rm -f ~/.zshrc.zwc.old
182                 [ -f ~/.zcompdump.zwc.old ] && rm -f ~/.zcompdump.zwc.old
183                 source ~/.zshrc
184 }
185
186 # Search for links in a directory and format the output
187 # Note: '~/.fnord.awk' is a *very* simple script based on >awk<.
188 #  ,----
189 #  | $ cat ~/bin/fnord.awk
190 #  |   BEGIN {
191 #  |     regexp = ""
192 #  |     regexp = regexp "((http|ftp)://)"
193 #  |     regexp = regexp  "[-0-9A-Za-z#%&+./:;?_~]"
194 #  |     regexp = regexp "*[-0-9A-Za-z#%&+/:;?_~]"
195 #  |   }
196 #  |   NF {
197 #  |        while (match($0, regexp))
198 #  |          {
199 #  |            print substr($0, RSTART, RLENGTH)
200 #  |             $0 = substr($0, RSTART + RLENGTH)
201 #  |          }
202 #  |      }
203 #  | END {}
204 #  `----
205 function URL-search()
206 {
207         if [[ $# = 0 ]]
208         then
209                 echo "Usage   : $0 directory"
210                 echo "Example : $0 ~/Mail"
211                 echo "Example : $0 directory | \$PAGER"
212                 echo "Example : $0 directory > logfile"
213         else
214                 egrep -r -h -i '((ftp|https|http|www):.*)' $1 | awk -f ~/bin/fnord.awk | sort | uniq 
215         fi
216 }
217
218 # Happy CVS'ing
219 function cvsd() { cvs diff -N $* |& $PAGER }
220 function cvsl() { cvs log $* |& $PAGER }
221 function cvsr() { rcs2log $* | $PAGER }
222 function cvss() { cvs status -v $* }
223 function cvsq() { cvs -nq update }
224 function cvsa() { cvs add $* && cvs com -m 'initial checkin' $* }
225
226 # Display the permissions in octal from given file. Not really needed.
227 # Use http://www.strcat.de/hacks/perm-oktal.pl instead
228 # function perm-oktal()
229 #{
230 #       echo $1 | perl -e 'chomp($s=<>);$p=(stat($s))[2] & 07777;printf "$s -> %04o\n",$p'
231 #}
232
233 # Translate DE<=>EN
234 # *narf* .. 'translate' looks up fot a word in a file with language-to-language
235 # translations (field separator should be " : "). A typical wordlist looks
236 # like at follows:
237 #  | english-word : german-transmission
238 # It's also only possible to translate english to german but not reciprocal.
239 # Use the following oneliner to turn back the sort order:
240 #  $ awk -F ':' '{ print $2" : "$1" "$3 }' \
241 #    /usr/local/lib/words/en-de.ISO-8859-1.vok > ~/.translate/de-en.ISO-8859-1.vok
242 function trans()
243 {
244         case "$1" in
245                 -[dD]*) translate -l de-en $2
246                 ;;
247                 -[eE]*) translate -l en-de $2
248                 ;;
249                 *)
250                 echo "Usage: $0 { -D | -E }"
251                 echo "         -D == German to English"
252                 echo "         -E == English to German"
253         esac
254 }
255
256 # Some quick Perl-hacks aka /useful/ oneliner
257 function bew() { perl -e 'print unpack "B*","'$1'"' ; perl -e 'print "\n"' }
258 function web() { perl -e 'print pack "B*","'$1'"' ; perl -e 'print "\n"' }
259 function hew() { perl -e 'print unpack "H*","'$1'"' ; perl -e 'print "\n"' }
260 function weh() { perl -e 'print pack "H*","'$1'"' ; perl -e 'print "\n"' }
261 function pversion() { perl -M$1 -le "print $1->VERSION" } # i. e."pversion LWP -> 5.79"
262 function getlinks () { perl -ne 'while ( m/"((www|ftp|http):\/\/.*?)"/gc ) { print $1, "\n"; }' $* }
263 function gethrefs () { perl -ne 'while ( m/href="([^"]*)"/gc ) { print $1, "\n"; }' $* }
264 function getanames () { perl -ne 'while ( m/a name="([^"]*)"/gc ) { print $1, "\n"; }' $* }
265 function getforms () { perl -ne 'while ( m:(\</?(input|form|select|option).*?\>):gic ) { print $1, "\n"; }' $* }
266 function getstrings () { perl -ne 'while ( m/"(.*?)"/gc ) { print $1, "\n"; }' $*}
267 function getanchors () { perl -ne 'while ( m/«([^«»\n]+)»/gc ) { print $1, "\n"; }' $* }
268 function showINC () { perl -e 'for (@INC) { printf "%d %s\n", $i++, $_ }' }
269 function vimpm () { vim `perldoc -l $1 | sed -e 's/pod$/pm/'` }
270 function vimhelp () { vim -c "help $1" -c on -c "au! VimEnter *" }
271
272 # set the DISPLAY to where i'm logged from or - if an argument is specified -
273 # to the value of the argument
274 function disp()
275 {
276         if [[ $# == 0 ]]
277         then
278                 DISPLAY=$(who am i | awk '{print $6}' | tr -d '()'):0
279         else
280                 DISPLAY="${*}:0"
281         fi
282         export DISPLAY
283 }
284
285 # adds a directory to the PATH, without making duplicate entries
286 function add_to_path()
287 {
288         if [[ "$1" == "" ]]
289         then
290                 echo "Usage: $0 directory"
291         else
292                 unset SPACEPATH
293                 local SPACEPATH
294                 for i in  ${(s.:.)PATH}
295         do
296                 SPACEPATH=( $SPACEPATH $i )
297         done
298         typeset -U SPACEPATH
299         if [[ -d "$1" ]]; then; SPACEPATH=( $SPACEPATH "$1" ); fi
300         PATH="`echo $SPACEPATH`"
301         PATH=${PATH:gs/ /:/}
302         export PATH
303         rehash
304 fi
305 }
306
307 # Shameless stolen from Sven Guckes (<http://www.guckes.net/setup/zshrc.mine>)
308 # _lap foo -- list all programs with prefix "foo":
309 function _lap()
310 {
311         if [[ $# = 0 ]]
312         then
313                 echo "Usage:    $0 program"
314                 echo "Example:  $0 zsh"
315                 echo "Lists all occurrences of program in the current PATH."
316         else
317                 ls -l ${^path}/*$1*(*N)
318         fi
319 }
320
321 # A life without 'diff'? Unimaginably!!!!11!
322 function mdiff() { diff -udrP "$1" "$2" > diff.`date "+%Y-%m-%d"`."$1" }
323 function udiff() { diff -urd $* | egrep -v "^Only in |^Binary files " }
324 function cdiff() { diff -crd $* | egrep -v "^Only in |^Binary files " }
325
326 # List / Search / Browse in a archive without unpack
327 function lynxbzgrep() { lynx -force_html -dump =(bzip2 -cd $1) | grep -i $2 }
328 function browse-archive() { lynx -force_html <( gzip -cd $1 ) }
329
330 # show/search signatures ;-)
331 # random-signature.pl can be found at
332 # <http://www.strcat.de/hacks/random-signature.pl>
333 function sig() 
334 {
335         if [[ $# = 0 ]]; then
336                 random-signature.pl; < ~/.signature
337         else
338                 agrep -d "^-- $" $@ ~/.sigs/own-stuff
339         fi
340 }
341
342 # mkdir && cd
343 function mcd() { mkdir "$1"; cd "$1" } 
344
345 # $ ls -l =ls
346 # $ -r-xr-xr-x    1 root     bin        167936 Oct  4  2002 /bin/ls
347 # $ pls ls
348 # $ -r-xr-xr-x    1 root     bin        167936 Oct  4  2002 /bin/ls 
349 function pls() { ls -l =$1 }
350
351 # cd && ls
352 function cl() { cd $1 && ls -a }
353
354 # Use vim to convert plaintext to HTML
355 function 2html() { vim -n -c ':so $VIMRUNTIME/syntax/2html.vim' -c ':wqa' $1 > /dev/null 2> /dev/null }
356
357 # Often needed (if i rape '$LS_COLORS' again *g*)
358 function _cols()
359 {
360         esc="\033["
361         echo -e "\t 40\t 41\t 42\t 43\t 44\t 45\t 46\t 47"
362         for fore in 30 31 32 33 34 35 36 37; do
363                 line1="$fore  "
364                 line2="    "
365                 for back in 40 41 42 43 44 45 46 47; do
366                         line1="${line1}${esc}${back};${fore}m Normal  ${esc}0m"
367                         line2="${line2}${esc}${back};${fore};1m Bold    ${esc}0m"
368                 done
369                 echo -e "$line1\n$line2"
370         done
371 }
372
373 # Usage: simple-extract <file>
374 # Description: extracts archived files (maybe)
375 simple-extract () 
376 {
377         if [[ -f $1 ]]
378         then
379                 case $1 in
380                         *.tar.bz2)  bzip2 -v -d $1      ;;
381                         *.tar.gz)   tar -xvzf $1        ;;
382                         *.rar)      unrar $1            ;;
383                         *.deb)      ar -x $1            ;;
384                         *.bz2)      bzip2 -d $1         ;;
385                         *.lzh)      lha x $1            ;;
386                         *.gz)       gunzip -d $1        ;;
387                         *.tar)      tar -xvf $1         ;;
388                         *.tgz)      gunzip -d $1        ;;
389                         *.tbz2)     tar -jxvf $1        ;;
390                         *.zip)      unzip $1            ;;
391                         *.Z)        uncompress $1       ;;
392                         *)          echo "'$1' Error. Please go away" ;;
393                 esac
394         else
395                 echo "'$1' is not a valid file"
396         fi
397 }
398
399 # Usage: smartcompress <file> (<type>)
400 # Description: compresses files or a directory.  Defaults to tar.gz
401 smartcompress()
402 {
403         if [ $2 ]; then
404                 case $2 in
405                         tgz | tar.gz)   tar -zcvf$1.$2 $1 ;;
406                         tbz2 | tar.bz2) tar -jcvf$1.$2 $1 ;;
407                         tar.Z)          tar -Zcvf$1.$2 $1 ;;
408                         tar)            tar -cvf$1.$2  $1 ;;
409                         gz | gzip)      gzip           $1 ;;
410                         bz2 | bzip2)    bzip2          $1 ;;
411                         *)
412                         echo "Error: $2 is not a valid compression type"
413                         ;;
414                 esac
415         else
416                 smartcompress $1 tar.gz
417         fi
418 }
419
420 # Usage: show-archive <archive>
421 # Description: view archive without unpack
422 show-archive()
423 {
424         if [[ -f $1 ]]
425         then
426                 case $1 in
427                         *.tar.gz)      gunzip -c $1 | tar -tf - -- ;;
428                         *.tar)         tar -tf $1 ;;
429                         *.tgz)         tar -ztf $1 ;;
430                         *.zip)         unzip -l $1 ;;
431                         *.bz2)         bzless $1 ;;
432                         *)             echo "'$1' Error. Please go away" ;;
433                 esac
434         else
435                 echo "'$1' is not a valid archive"
436         fi
437 }
438
439 # find process and kill it
440 morons() { reply=(`ps ax | grep -v COMMAND |perl -nle '@a=split(" ",$_,9);$_=$a[4];s/[()]//g;s/.*\///g;print'`) }
441 compctl -K morons pskill pkill
442 pskill()
443 {
444         local signal="HUP"
445         if [[ $1 == "" || $3 != "" ]]; then
446                 print "Usage: $0 processname [signal]" && return 1
447         fi
448         [[ $2 != "" ]] && signal=$2
449         set -A pids $(command ps wwaux | grep $1 | grep -v "grep $1" | awk '{ print $2 }')
450         if [[ ${#pids} -lt 1 ]]; then
451                 print "No matching processes for Â»$1«" && return 1
452         fi
453         if [[ ${#pids} -gt 1 ]]; then
454                 print "${#pids} processes matched: $pids"
455                 read -q "?Kill all? [y/n] " || return 0
456         fi
457         if kill -$signal $pids; then
458                 echo "Killed $1 pid $pids with SIG$signal"
459         fi
460 }
461
462 # Use 'view' to read manpages, if u want colors, regex - search, ...
463 # like vi(m).
464 # It's shameless stolen from <http://www.vim.org/tips/tip.php?tip_id=167>
465 function vman() { man $* | col -b | view -c 'set ft=man nomod nolist' - }
466
467 # J-E-H-O-V-A!!!11!!
468 #  ,----
469 #  |  $ (cd $PORTS_DIR && make print-index ~/.ports)
470 #  |  $ grep -i "^Port.*xchat-" -B1 -A8 .ports
471 #  |
472 #  |    Port:   xchat-1.8.11
473 #  |    Path:   net/xchat
474 #  |    Info:   X-Chat is an X11 IRC client
475 #  |    Maint:  Damien Couderc <couderc@openbsd.org>
476 #  |    Index:  net x11
477 #  |    L-deps: gdk_pixbuf::graphics/gdk-pixbuf iconv.2::converters/libiconv intl.1:gettext->=0.10.38:devel/gettext
478 #  |    B-deps: :devel/gmake bzip2-*:archivers/bzip2 gettext->=0.10.38:devel/gettext
479 #  |    R-deps: gettext->=0.10.38:devel/gettext libiconv-*:converters/libiconv
480 #  |
481 #  `----
482 if [ "${OS}" = openbsd ]; then
483         function port() 
484         {
485                 case "$1" in
486                         -p) =grep -i "^Port.*$2" -B1 -A8 ~/.ports
487                         ;;
488                         -i) =grep -i "^Info.*$2" -B1 -A5 ~/.ports
489                         ;;
490                         *)
491                         echo "Usage: $0 {-i | -p } string }"
492                         echo "       -i (Info)       Search parse Info:"
493                         echo "       -p (Port)       Search parse Port:"
494                 esac
495         }
496 fi
497
498 # Exchange ' ' for '_' in filenames.
499 unspaceit()
500 {
501         for _spaced in "${@:+"$@"}"; do
502                 if [ ! -f "${_spaced}" ]; then
503                         continue;
504                 fi
505                 _underscored=$(echo ${_spaced} | tr ' ' '_');
506                 if [ "${_underscored}" != "${_spaced}" ]; then
507                         mv "${_spaced}" "${_underscored}";
508                 fi
509         done
510 }
511
512 # summarized google, ggogle, mggogle, agoogle and fm
513 function search()
514 {
515         case "$1" in
516                 -g) ${BROWSER:-lynx} "http://www.google.com/search?q="$2""
517                 ;;
518                 -u) ${BROWSER:-lynx} "http://groups.google.com/groups?q="$2""
519                 ;;
520                 -m) ${BROWSER:-lynx} "http://groups.google.com/groups?selm="$2""
521                 ;;
522                 -a) ${BROWSER:-lynx} "http://groups.google.com/groups?as_uauthors="$2""
523                 ;;
524                 -c) ${BROWSER:-lynx} "http://search.cpan.org/search?query="$2"&mode=module"
525                 ;;
526                 -f) ${BROWSER:-lynx} "http://freshmeat.net/search/?q=$2&section=projects"
527                 ;;
528                 -F) ${BROWSER:-lynx} "http://www.filewatcher.com/?q="$2""
529                 ;;
530                 -s) ${BROWSER:-lynx} "http://sourceforge.net/search/?type=soft&q="$2""
531                 ;;
532                 *) 
533                   echo "Usage: $0 {-g | -u | -m | -a | -f | -c | -F}"
534                   echo "        -g: Searching for keyword in google.com"
535                   echo "        -u: Searching for keyword in groups.google.com"
536                   echo "        -m: Searching for message-id in groups.google.com"
537                   echo "        -a: Searching for Authors in groups.google.com"
538                   echo "        -c: Searching for Modules on cpan.org."
539                   echo "        -f: Searching for projects on Freshmeat."
540                   echo "        -F: Searching for packages on FileWatcher."
541                   echo "        -s: Searching for software on Sourceforge."
542         esac
543 }
544
545 # Quick&dirty hack to read heise-news (<http://www.heise.de/>
546 function heise()
547 {
548         CURDIR=${pwd};
549         cd /tmp;
550         if [[ -s tmp/heise.rdf ]]
551                 then
552                         rm heise.rdf
553                 fi
554                 wget -q -O - http://heise.de/newsticker/heise.rdf |\
555                 sed -e '/title/!d;s, <title>\(.*\)</title>,\1,' -e '/heise online/d' ; 
556                 cd $CURDIR
557 }
558
559 # make screenshot of current desktop (use 'import' from ImageMagic)
560 # See man date(1) and man import(1) for details.
561 # Note: If you don't have 'import', install ImageMagick and stop
562 #       crying.
563 function sshot() 
564
565         [[ ! -d ~/shots  ]] && mkdir ~/shots
566         cd ~/shots ; sleep 5 ; import -window root -depth 8 -quality 80 `date "+%Y-%m-%d%--%H:%M:%S"`.png
567 #       cd ~/shots && sleep 5; import -window root `date "+%Y-%m-%d%--%H:%M:%S"`.jpg
568
569 }
570
571 # Needs ImageMagick
572 function gif2png() 
573 {
574         if [[ $# = 0 ]]
575         then
576                 echo "Usage: $0 foo.gif"
577                 echo "Purpose: change a GIF file to a PNG file"
578         else
579                 output=`basename $1 .gif`.png
580                 convert  $1 $output
581                 touch -r $1 $output
582                 ls -l $1 $output
583         fi
584 }
585
586 # search for various types or README file in dir and display them in $PAGER
587 # function readme() { $PAGER -- (#ia3)readme* }
588 function readme()
589 {
590         local files
591         files=(./(#i)*(read*me|lue*m(in|)ut)*(ND))
592         if (($#files))
593         then $PAGER $files
594         else
595                 print 'No README files. Please lart \$MAINTAINER!'
596         fi
597 }
598
599 # find all suid files in $PATH
600 function suidfind() { ls -latg ${(s.:.)PATH} | grep '^...s' }
601
602 # See above but this is /better/ ... anywise ..
603 #  Note: Add $USER and 'find' with "NOPASSWD" in your /etc/sudoers or run it
604 #        as root (UID == 0)
605 function findsuid()
606 {
607         sudo find / -type f \( -perm -4000 -o -perm -2000 \) -ls > ~/.suid/suidfiles.`date "+%Y-%m-%d"`.out 2>&1
608         sudo find / -type d \( -perm -4000 -o -perm -2000 \) -ls > ~/.suid/suiddirs.`date "+%Y-%m-%d"`.out 2>&1
609         sudo find / -type f \( -perm -2 -o -perm -20 \) -ls > ~/.suid/writefiles.`date "+%Y-%m-%d"`.out 2>&1
610         sudo find / -type d \( -perm -2 -o -perm -20 \) -ls > ~/.suid/writedirs.`date "+%Y-%m-%d"`.out 2>&1
611 }
612
613 # csh compatibility
614 setenv() { typeset -x "${1}${1:+=}${(@)argv[2,$#]}" }
615
616 # if [ Now-Playing == "relaxmusic" ];then .. ;-)
617 beer()
618 {
619         echo "         _.._..,_,_"
620         echo "        (          )"
621         echo "         ]~,\"-.-~~["
622         echo "       .=])' (;  ([    PANTS OFF!"
623         echo "       | ]:: '    ["
624         echo "       '=]): .)  (["
625         echo "         |:: '    |"
626         echo "          ~~----~~"
627 }
628
629 # Add directory to a bookmark-list
630 # % bmadd       # add directory to bookmark list
631 # % bmls        # show list of bookmark list
632 # % bmvi        # edit bookmark list
633 # % bm $NUMBER  # change directory to $NUMBER bookmark
634 BMRC=~/.bmrc
635 /usr/bin/touch $BMRC
636 bmls() { cat $BMRC | sort -n}
637 bmvi() { vi $BMRC }
638 bmadd() {
639         local bmdir=`pwd`
640         local newid=$1
641         local bmname=''
642         for bmname in `bm_path_list`
643         do
644                 if [ "$bmname" = "$bmdir" ]; then
645                         echo "$bmdir is already in bm list"
646                         return
647                 fi
648         done
649         if [ -z $newid ]; then
650                 maxid=`cat $BMRC | cut -f 1 | sort -n -r | head -1`
651                 if [ "$maxid" -ge 1 ]; then
652                         newid=`expr 0$maxid + 1`
653                 else
654                         newid=1
655                 fi
656         fi
657         echo "$newid\t$bmdir" >> $BMRC
658 }
659 bm() {
660         local num=$1
661         local bmdir=`bm_get $num`
662         if [ -z "$bmdir" ]; then
663                 bmls     
664                 [ -z "$num" ] || echo "$num is not in bm list"
665                 return
666         fi
667         cd "$bmdir"
668 }
669 bm_get() {
670         local bmdir=`cat $BMRC | egrep "^${1}[[:space:]]" | cut -f 2`
671         echo $bmdir
672 }
673
674 bm_path_list() {
675         cut -f 2 < $BMRC
676 }
677
678 # Temporary (interactive) removes. Alternative to this u can use
679 # http://www.strcat.de/hacks/rm-replacements.shar
680 function rf()
681 {
682         [[ -z ${SHITDIR} ]] && print "No ${SHITDIR} defined." && return 1
683         [[ ! -d ${SHITDIR} ]] && mkdir ${SHITDIR}
684         mv $* ${SHITDIR}
685 }
686
687 # Reload functions.
688 function refunc()
689 {
690         for func in $argv
691         do
692                 unfunction $func
693                 autoload $func
694         done
695 }
696
697 # a small check to see which DIR is located on which server/partition.
698 # stolen and modified from Sven's zshrc.forall
699 function dirspace()
700 {
701         for dir in ${(s.:.)PATH};
702         do
703                 (cd $dir; echo "-<$dir>"; du -shx .; echo);
704         done
705 }
706
707 # Create a archive for my homepage (<http://strcat.neessen.net/>)
708 function mkz()
709 {
710         cd ~/homepage/dotfiles/zsh
711         cp ~/.zlogin ~/homepage/dotfiles/zsh/zlogin
712         cp ~/.zlogout ~/homepage/dotfiles/zsh/zlogout
713         cp ~/.zshrc ~/homepage/dotfiles/zsh/zshrc
714         cp ~/.zsh/z* ~/homepage/dotfiles/zsh/
715         cd ~/homepage/dotfiles/zsh/
716         rm ~/homepage/dotfiles/zsh/zshdevel.old
717         tar cf dot-zsh.tar * 
718         gzip --best ~/homepage/dotfiles/zsh/dot-zsh.tar
719         cd ~1
720 }
721
722 # FIXME: works not so as i like
723 #--------------------------------------------------
724 # function verify() {
725 #         for i in "$1"
726 #         do
727 #                 if [ -r "$1" ]
728 #                 then
729 #                   #cd `dirname $1`
730 #                   cd =$1(:h)
731 #                 shortname=`basename $1`
732 #                   md5 "$shortname" > "~/.checksums/$shortname.md5sum"
733 #                   echo "Verified $shortname to $shortname.md5sum"
734 #                 else
735 #                   echo "Can not find $1"
736 #                 fi
737 #         done
738 # }
739 #-------------------------------------------------- 
740
741
742 # Find (and print) all symbolic links without a target within the
743 # current directorytree (i. e. ll symlinks that dont point to files,
744 # directories, sockets, devices, or named pipes).
745 # Note: all three functions works but the last is nicer
746 # function brlinks() { for i in **/*(D@); [[ -f $i || -d $i ]] || echo $i }
747 # function brlinks() { print -l **/*(@-^./=%p) }
748 function brlinks() { print -l **/*(-@) }
749
750 # *fg*
751 # function show_print () {
752 #    for argument in "${@}"
753 #      do
754 #for ((i = 1; i <= ${#1} ;i++)) {
755 #    print -n "${argument[i]}"
756 #    sleep 0.005
757 #}
758 #print -n " "
759 #      done
760 #    print ""
761 #}
762
763 # display some informations
764 function status()
765 {
766         print ""
767         print "Date..: "$(date "+%Y-%m-%d %H:%M:%S")""
768         print "Shell.: Zsh $ZSH_VERSION (PID = $$, $SHLVL nests)"
769         print "Term..: $TTY ($TERM), $BAUD bauds, $COLUMNS x $LINES cars"
770         print "Login.: $LOGNAME (UID = $EUID) on $HOST"
771         print "System: $(cat /etc/[A-Za-z]*[_-][rv]e[lr]*)"
772         print "Uptime:$(uptime)"
773         print ""
774 }
775
776 # a fucking lazy poor man clock..
777 # check time every minute
778 # PERIOD=60
779 # show time every 15 minutes
780 #function periodic()
781 #{
782 #       if [ `date +'%M'` = '00' ] ||
783 #               [ `date +'%M'` = '15' ] ||
784 #               [ `date +'%M'` = '30' ] ||
785 #               [ `date +'%M'` = '45' ]
786 #       then
787 #               echo Time: `date +'%H:%M'`
788 #       fi
789 #}
790
791 # For my Linux boxes
792 if [ ${OS} = linux-gnu ]; then
793 function mkernel() 
794 {
795         make clean && make dep && make modules && make modules_install && make bzImage
796         cd arch/i386/boot
797 }
798
799 function getkernel()
800 {
801         if [ $# -ne 3 ] ; then
802                 echo "Usage:"
803                 echo "$0 MAJOR MINOR SUBMINOR"
804                 echo ""
805                 echo "eg:"
806                 echo "   $0 2 6 7"
807                 latest=`echo -e "GET /kdist/finger_banner HTTP/1.0\n" | netcat www.kernel.org 80 | sed -ne "/^\r$/,//p"`
808                 echo ""
809                 echo "current versions: $latest"
810                 echo ""
811                 echo -n 'Used release is: '
812                 uname -r
813         else
814                 cd /Source
815                 SERVER=http://www.de.kernel.org/pub/linux/kernel/
816                 KERNEL=$SERVER/v$1.$2/linux-$1.$2.$3.tar.bz2
817                 SIGN=$SERVER/v$1.$2/linux-$1.$2.$3.tar.bz2.sign
818                 echo 'starting download'
819                 wget -c $KERNEL &&
820                 wget -c $SIGN   &&
821                 echo 'done'
822                 echo 'checking signature:'
823                 gpg --verify `basename $SIGN $KERNEL` &&
824                 echo 'done'
825         fi
826 }
827
828 function audiorip()
829 {
830         mkdir -p ~/ripps
831         cd ~/ripps
832         cdrdao read-cd --device $DEVICE --driver generic-mmc audiocd.toc
833         cdrdao read-cddb --device $DEVICE --driver generic-mmc audiocd.toc
834         echo " * Would you like to burn the cd now? (yes/no)"
835         read input
836         if
837                 [ "$input" = "yes" ]; then
838                 echo " ! Burning Audio CD"
839                 audioburn
840                 echo " * done."
841         else
842                 echo " ! Invalid response."
843         fi
844 }
845
846 function audioburn()
847 {
848         cd ~/ripps
849         cdrdao write --device $DEVICE --driver generic-mmc audiocd.toc
850         echo " * Should I remove the temporary files? (yes/no)"
851         read input
852         if [ "$input" = "yes" ]; then
853                 echo " ! Removing Temporary Files."
854                 cd ~
855                 rm -rf ~/ripps
856                 echo " * done."
857         else
858                 echo " ! Invalid response."
859         fi
860 }
861
862 function mkaudiocd()
863 {
864         cd ~/ripps
865         for i in *.[Mm][Pp]3; do mv "$i" `echo $i | tr '[A-Z]' '[a-z]'`; done
866         for i in *.mp3; do mv "$i" `echo $i | tr ' ' '_'`; done 
867         for i in *.mp3; do mpg123 -w `basename $i .mp3`.wav $i; done 
868         normalize -m *.wav
869         for i in *.wav; do sox $i.wav -r 44100 $i.wav resample; done
870 }
871
872 function mkiso()
873 {
874         echo " * Volume name "
875         read volume
876         echo " * ISO Name (ie. tmp.iso)"
877         read iso
878         echo " * Directory or File"
879         read files
880         mkisofs -o ~/$iso -A $volume -allow-multidot -J -R -iso-level 3 -V $volume -R $files
881 }
882
883 # rmmodcomplete() looks for modules in memory, for use with "rmmod".
884 rmmodcomplete () { reply=(`/sbin/lsmod|cut -f1 -d" "|grep -v Module`) }
885 compctl -K rmmodcomplete rmmod
886
887 # insmodcomplete() looks for modules to use with "insmod" or
888 # "modprobe".
889 function insmodcomplete() { reply=(`find /lib/modules/$(uname -r)/* ! -type d -printf "%f\n"|sed "s/\.o$//"`) }
890 compctl -K insmodcomplete insmod modprobe
891
892 fi
893
894 # Complete a howto-filename or FAQ-name (see howto script below).
895 # Use like "howto zsh[TAB]".
896 function howtocomplete() { reply=(`howto --find "$1"`) }
897 compctl -U -K howtocomplete howto
898 p0rncomplete() { reply=(`p0rn --find "$1"`) }
899 compctl -U -K p0rncomplete p0rn
900
901 # a quick hack for GNU Emacs && emacsclient
902 function e()
903 {
904         if [ "$1" = "" ]; then
905                 echo "No file specified you have, think before you must."
906         else
907                 if emacsclient -n "$1" >/dev/null 2>&1; then
908                         echo "Alrite, opened $1 in the Holy Emacs."
909                 else
910                         echo "There's no Holy Emacs running here.. starting.."
911                         exec emacs "$1" &
912                 fi
913         fi
914 }
915
916 # Show days since given birthday
917 function days () 
918 {
919         if [ "$*" = "" ]; then
920                 echo "Use $0 day month year"
921                 echo "Example: $0 "12 aug 1999""
922         else
923                 BIRTHDAY="$*"
924                 print $(( (`date +%s -d ${2:="now"}` - `date +%s -d ${1:=$BIRTHDAY}` )/60/60/24 ))
925         fi
926 }
927
928 # generate thumbnails ;)
929 function genthumbs ()
930 {
931     rm -rf thumb-* index.html
932     echo "
933 <html>
934   <head>
935     <title>Images</title>
936   </head>
937   <body>" > index.html
938     for f in *.(gif|jpeg|jpg|png)
939     do
940         convert -size 100x200 "$f" -resize 100x200 thumb-"$f"
941         echo "    <a href=\"$f\"><img src=\"thumb-$f\"></a>" >> index.html
942     done
943     echo "
944   </body>
945 </html>" >> index.html
946 }