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 Jun 05 21:06:19 CEST 2005 [mika]
7 ################################################################################
9 # See /etc/zsh/zshrc for some general settings
13 # set terminal property (used e.g. by msgid-chooser)
14 export COLORTERM="yes"
17 (( ${+BROWSER} )) || export BROWSER="w3m"
18 (( ${+PAGER} )) || export PAGER="less"
23 # Allow comments even in interactive shells i. e.
24 # $ uname # This command prints system informations
26 # $ setopt interactivecomments
27 # $ uname # This command prints system informations
29 # setopt interactivecomments
34 # These do not have to be at the beginning of the command line.
35 # Avoid typing cd ../../ for going two dirs down and so on
36 # Usage, e.g.: "$ cd ...' or just '$ ...' with 'setopt auto_cd'
37 alias -g '...'='../..'
38 alias -g '....'='../../..'
39 # Usage is "$ somecommand C (this pipes it into 'wc -l'):
44 alias -g Hl=' --help |& less -r'
48 alias -g N='&>/dev/null'
49 alias -g R='| tr A-z N-za-m'
50 alias -g SL='| sort | less'
61 # alias u='translate -i' # translate
64 alias CO="./configure"
65 alias CH="./configure --help"
67 # http://conkeror.mozdev.org/
68 alias conkeror='firefox -chrome chrome://conkeror/content'
71 alias ldiff='tla what-changed --diffs | less'
72 alias tbp='tla-buildpackage'
73 alias mirror='tla archive-mirror'
74 alias commit='tla commit'
75 alias merge='tla star-merge'
79 alias lad='ls -d .*(/)' # only show dot-directories
80 alias lsa='ls -a .*(.)' # only show dot-files
81 alias lss='ls -l *(s,S,t)' # only files with setgid/setuid/sticky flag
82 alias lsl='ls -l *(@[1,10])' # only symlinks
83 alias lsx='ls -l *(*[1,10])' # only executables
84 alias lsw='ls -ld *(R,W,X.^ND/)' # world-{readable,writable,executable} files
85 alias lsbig="ls -flh *(.OL[1,10])" # display the biggest files
86 alias lsd='ls -d *(/)' # only show directories
87 alias lse='ls -d *(/^F)' # only show empty directories
88 alias lsnew="ls -rl *(D.om[1,10])" # display the newest files
89 alias lsold="ls -rtlh *(D.om[1,10])" # display the oldest files
90 alias lssmall="ls -Srl *(.oL[1,10])" # display the smallest files
102 alias cmplayer='mplayer -vo fbdev'
103 alias fbmplayer='mplayer -vo fbdev'
104 alias fblinks='links2 -driver fb'
106 # use colors when browsing man pages (if not using pinfo or PAGER=most)
107 [ -d ~/.terminfo/ ] && alias man='TERMINFO=~/.terminfo/ LESS=C TERM=mostlike PAGER=less man'
111 ## useful functions {{{
113 # functions without detailed explanation:
114 agoogle() { $BROWSER "http://groups.google.com/groups?as_uauthors=$*" ; }
115 bk() { cp -b ${1} ${1}_`date --iso-8601=m` }
116 cdiff() { diff -crd "$*" | egrep -v "^Only in |^Binary files " }
117 cl() { cd $1 && ls -a } # cd && ls
118 cvsa() { cvs add $* && cvs com -m 'initial checkin' $* }
119 cvsd () { cvs diff -N $* |& $PAGER }
120 cvsl () { cvs log $* |& $PAGER }
121 cvsq () { cvs -nq update }
122 cvsr () { rcs2log $* | $PAGER }
123 cvss () { cvs status -v $* }
124 debbug () { $BROWSER "http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=$*" }
125 disassemble(){ gcc -pipe -S -o - -O -g $* | as -aldh -o /dev/null }
126 dwicti() { $BROWSER http://de.wiktionary.org/wiki/${(C)1// /_} }
127 ewicti() { $BROWSER http://en.wiktionary.org/wiki/${(C)1// /_} }
128 ggogle() { $BROWSER "http://groups.google.com/groups?q=$*" }
129 google() { $BROWSER "http://www.google.com/search?&num=100&q=$*" }
130 leo() { $BROWSER "http://dict.leo.org/?search=$*" }
131 mdiff() { diff -udrP "$1" "$2" > diff.`date "+%Y-%m-%d"`."$1" }
132 memusage(){ ps aux | awk '{if (NR > 1) print $5; if (NR > 2) print "+"} END { print "p" }' | dc }
133 mggogle() { $BROWSER "http://groups.google.com/groups?selm=$*" }
134 shtar() { gunzip -c $1 | tar -tf - -- | $PAGER }
135 shtgz() { tar -ztf $1 | $PAGER }
136 shzip() { unzip -l $1 | $PAGER }
137 sig() { agrep -d '^-- $' "$*" ~/.Signature }
138 udiff() { diff -urd $* | egrep -v "^Only in |^Binary files " }
139 wikide() { $BROWSER http://de.wikipedia.org/wiki/"$*" }
140 wikien() { $BROWSER http://en.wikipedia.org/wiki/"$*" }
146 sudo apt-get -u upgrade
148 ssh $1 sudo apt-get update
149 # ask before the upgrade
151 ssh $1 sudo apt-get --no-act upgrade
152 echo -n "Process the upgrade ?"
154 if [[ $dummy == "y" ]] ; then
155 ssh $1 sudo apt-get -u upgrade --yes
160 # make screenshot of current desktop (use 'import' from ImageMagic)
162 [[ ! -d ~/shots ]] && mkdir ~/shots
163 #cd ~/shots ; sleep 5 ; import -window root -depth 8 -quality 80 `date "+%Y-%m-%d--%H:%M:%S"`.png
164 cd ~/shots ; sleep 5; import -window root shot_`date --iso-8601=m`.jpg
167 # create pdf file from source code
171 a2ps --medium A4dj -E -o $output $*
175 # zsh with perl-regex - use it e.g. via:
176 # regcheck '\s\d\.\d{3}\.\d{3} Euro' ' 1.000.000 Euro'
180 pcre_match $2 && echo "regex matches" || echo "regex does not match"
182 # list files which have been modified within the last x days
183 new() { print -l *(m-$1) }
186 greph () { history 0 | grep $1 }
187 alias grepc='grep --color=auto'
188 alias GREP='grep -i --color=auto'
190 # one blank line between each line
191 man2() { PAGER='sed G | less' /usr/bin/man $* ; }
193 # provide useful information on globbing
200 p named pipes (FIFOs)
201 * executable plain files (0100)
202 % device files (character or block special)
203 %b block special files
204 %c character special files
205 r owner-readable files (0400)
206 w owner-writable files (0200)
207 x owner-executable files (0100)
208 A group-readable files (0040)
209 I group-writable files (0020)
210 E group-executable files (0010)
211 R world-readable files (0004)
212 W world-writable files (0002)
213 X world-executable files (0001)
214 s setuid files (04000)
215 S setgid files (02000)
216 t files with the sticky bit (01000)
217 print *(m-1) # Dateien, die vor bis zu einem Tag modifiziert wurden.
218 print *(a1) # Dateien, auf die vor einem Tag zugegriffen wurde.
219 print *(@) # Nur Links
220 print *(Lk+50) # Dateien die ueber 50 Kilobytes grosz sind
221 print *(Lk-50) # Dateien die kleiner als 50 Kilobytes sind
222 print **/*.c # Alle *.c - Dateien unterhalb von \$PWD
223 print **/*.c~file.c # Alle *.c - Dateien, aber nicht 'file.c'
224 print (foo|bar).* # Alle Dateien mit 'foo' und / oder 'bar' am Anfang
225 print *~*.* # Nur Dateien ohne '.' in Namen
226 chmod 644 *(.^x) # make all non-executable files publically readable
227 print -l *(.c|.h) # Nur Dateien mit dem Suffix '.c' und / oder '.h'
228 print **/*(g:users:) # Alle Dateien/Verzeichnisse der Gruppe >users<
229 echo /proc/*/cwd(:h:t:s/self//) # Analog zu >ps ax | awk '{print $1}'<"
233 nm -go /usr/lib/lib*.a 2>/dev/null | grep ":[[:xdigit:]]\{8\} . .*$1"":[[:xdigit:]]\{8\} . .*$1"
238 FILES=(*~(N) .*~(N) \#*\#(N) *.o(N) a.out(N) *.core(N) *.cmo(N) *.cmi(N) .*.swp(N))
240 if [[ $NBFILES > 0 ]]; then
243 echo -n "Remove this files? [y/n] "
248 echo ">> $PWD purged, $NBFILES files removed"
250 echo "Ok. .. than not.."
256 # 'translate' looks up fot a word in a file with language-to-language
257 # translations (field separator should be " : "). A typical wordlist looks
259 # | english-word : german-transmission
260 # It's also only possible to translate english to german but not reciprocal.
261 # Use the following oneliner to turn back the sort order:
262 # $ awk -F ':' '{ print $2" : "$1" "$3 }' \
263 # /usr/local/lib/words/en-de.ISO-8859-1.vok > ~/.translate/de-en.ISO-8859-1.vok
266 -[dD]*) translate -l de-en $2
268 -[eE]*) translate -l en-de $2
271 echo "Usage: $0 { -D | -E }"
272 echo " -D == German to English"
273 echo " -E == English to German"
277 # Some quick Perl-hacks aka /useful/ oneliner
278 # bew() { perl -le 'print unpack "B*","'$1'"' }
279 # web() { perl -le 'print pack "B*","'$1'"' }
280 # hew() { perl -le 'print unpack "H*","'$1'"' }
281 # weh() { perl -le 'print pack "H*","'$1'"' }
282 # pversion() { perl -M$1 -le "print $1->VERSION" } # i. e."pversion LWP -> 5.79"
283 # getlinks () { perl -ne 'while ( m/"((www|ftp|http):\/\/.*?)"/gc ) { print $1, "\n"; }' $* }
284 # gethrefs () { perl -ne 'while ( m/href="([^"]*)"/gc ) { print $1, "\n"; }' $* }
285 # getanames () { perl -ne 'while ( m/a name="([^"]*)"/gc ) { print $1, "\n"; }' $* }
286 # getforms () { perl -ne 'while ( m:(\</?(input|form|select|option).*?\>):gic ) { print $1, "\n"; }' $* }
287 # getstrings () { perl -ne 'while ( m/"(.*?)"/gc ) { print $1, "\n"; }' $*}
288 # getanchors () { perl -ne 'while ( m/«([^«»\n]+)»/gc ) { print $1, "\n"; }' $* }
289 # showINC () { perl -e 'for (@INC) { printf "%d %s\n", $i++, $_ }' }
290 # vimpm () { vim `perldoc -l $1 | sed -e 's/pod$/pm/'` }
291 # vimhelp () { vim -c "help $1" -c on -c "au! VimEnter *" }
293 # plap foo -- list all occurrences of program in the current PATH
297 echo "Usage: $0 program"
298 echo "Example: $0 zsh"
299 echo "Lists all occurrences of program in the current PATH."
301 ls -l ${^path}/*$1*(*N)
305 # Found in the mailinglistarchive from Zsh (IIRC ~1996)
310 echo "Usage: $0 command"
313 cmd=(${(f)"$(grep -w $1 $HISTFILE | sort | uniq | pr -tn)"})
314 print -l $cmd | less -F
315 echo -n "enter number of desired command [1 - $(( ${#cmd[@]} - 1 ))]: "
318 print -z "${cmd[$answer]#*$TAB}"
322 mcd() { mkdir -p "$@"; cd "$@" } # mkdir && cd
325 cl() { cd $1 && ls -a }
327 # Use vim to convert plaintext to HTML
328 2html() { vim -u NONE -n -c ':syntax on' -c ':so $VIMRUNTIME/syntax/2html.vim' -c ':wqa' $1 > /dev/null 2> /dev/null }
330 # Usage: simple-extract <file>
331 # Description: extracts archived files (maybe)
336 *.tar.bz2) bzip2 -v -d $1 ;;
337 *.tar.gz) tar -xvzf $1 ;;
340 *.bz2) bzip2 -d $1 ;;
342 *.gz) gunzip -d $1 ;;
343 *.tar) tar -xvf $1 ;;
344 *.tgz) gunzip -d $1 ;;
345 *.tbz2) tar -jxvf $1 ;;
347 *.Z) uncompress $1 ;;
348 *) echo "'$1' Error. Please go away" ;;
351 echo "'$1' is not a valid file"
355 # Usage: smartcompress <file> (<type>)
356 # Description: compresses files or a directory. Defaults to tar.gz
360 tgz | tar.gz) tar -zcvf$1.$2 $1 ;;
361 tbz2 | tar.bz2) tar -jcvf$1.$2 $1 ;;
362 tar.Z) tar -Zcvf$1.$2 $1 ;;
363 tar) tar -cvf$1.$2 $1 ;;
364 gz | gzip) gzip $1 ;;
365 bz2 | bzip2) bzip2 $1 ;;
367 echo "Error: $2 is not a valid compression type"
371 smartcompress $1 tar.gz
375 # Usage: show-archive <archive>
376 # Description: view archive without unpack
381 *.tar.gz) gunzip -c $1 | tar -tf - -- ;;
383 *.tgz) tar -ztf $1 ;;
384 *.zip) unzip -l $1 ;;
386 *) echo "'$1' Error. Please go away" ;;
389 echo "'$1' is not a valid archive"
394 if [[ -e $1 || -h $1 ]]; then
399 if [[ -e $file || -L $file ]]; then
400 if [[ -L $file ]]; then
401 echo `ls -ld $file | perl -ane 'print $F[7]'` '->'
402 folsym `perl -le '$file = $ARGV[0];
403 $dest = readlink $file;
404 if ($dest !~ m{^/}) {
405 $file =~ s{(/?)[^/]*$}{$1$dest};
409 $file =~ s{/{2,}}{/}g;
410 while ($file =~ s{[^/]+/\.\./}{}) {
413 $file =~ s{^(/\.\.)+}{};
423 # Use 'view' to read manpages, if u want colors, regex - search, ...
425 # It's shameless stolen from <http://www.vim.org/tips/tip.php?tip_id=167>
426 vman() { man $* | col -b | view -c 'set ft=man nomod nolist' - }
428 # search for various types or README file in dir and display them in $PAGER
429 # function readme() { $PAGER -- (#ia3)readme* }
432 files=(./(#i)*(read*me|lue*m(in|)ut)*(ND))
436 print 'No README files.'
440 # find all suid files in $PATH
441 suidfind() { ls -latg $path | grep '^...s' }
443 # See above but this is /better/ ... anywise ..
444 # Note: Add $USER and 'find' with "NOPASSWD" in your /etc/sudoers or run it
447 if [ UID != 0 ] ; then
448 print 'Not running as root. Trying to run via sudo...'
451 print 'Output will be written to ~/suid_* ...'
452 $RUNASROOT find / -type f \( -perm -4000 -o -perm -2000 \) -ls > ~/suid_suidfiles.`date "+%Y-%m-%d"`.out 2>&1
453 $RUNASROOT find / -type d \( -perm -4000 -o -perm -2000 \) -ls > ~/suid_suiddirs.`date "+%Y-%m-%d"`.out 2>&1
454 $RUNASROOT find / -type f \( -perm -2 -o -perm -20 \) -ls > ~/suid_writefiles.`date "+%Y-%m-%d"`.out 2>&1
455 $RUNASROOT find / -type d \( -perm -2 -o -perm -20 \) -ls > ~/suid_writedirs.`date "+%Y-%m-%d"`.out 2>&1
468 # a small check to see which DIR is located on which server/partition.
469 # stolen and modified from Sven's zshrc.forall
473 (cd $dir; echo "-<$dir>"; du -shx .; echo);
477 # $ show_print `cat /etc/passwd`
479 for argument in "${@}"
481 for ((i = 1; i <= ${#1} ;i++)) {
482 print -n "${argument[i]}"
492 print "Date..: "$(date "+%Y-%m-%d %H:%M:%S")""
493 print "Shell.: Zsh $ZSH_VERSION (PID = $$, $SHLVL nests)"
494 print "Term..: $TTY ($TERM), $BAUD bauds, $COLUMNS x $LINES cars"
495 print "Login.: $LOGNAME (UID = $EUID) on $HOST"
496 print "System: $(cat /etc/[A-Za-z]*[_-][rv]e[lr]*)"
497 print "Uptime:$(uptime)"
504 cdrdao read-cd --device $DEVICE --driver generic-mmc audiocd.toc
505 cdrdao read-cddb --device $DEVICE --driver generic-mmc audiocd.toc
506 echo " * Would you like to burn the cd now? (yes/no)"
509 [ "$input" = "yes" ]; then
510 echo " ! Burning Audio CD"
514 echo " ! Invalid response."
520 cdrdao write --device $DEVICE --driver generic-mmc audiocd.toc
521 echo " * Should I remove the temporary files? (yes/no)"
523 if [ "$input" = "yes" ]; then
524 echo " ! Removing Temporary Files."
529 echo " ! Invalid response."
535 for i in *.[Mm][Pp]3; do mv "$i" `echo $i | tr '[A-Z]' '[a-z]'`; done
536 for i in *.mp3; do mv "$i" `echo $i | tr ' ' '_'`; done
537 for i in *.mp3; do mpg123 -w `basename $i .mp3`.wav $i; done
539 for i in *.wav; do sox $i.wav -r 44100 $i.wav resample; done
543 echo " * Volume name "
545 echo " * ISO Name (ie. tmp.iso)"
547 echo " * Directory or File"
549 mkisofs -o ~/$iso -A $volume -allow-multidot -J -R -iso-level 3 -V $volume -R $files
552 # generate thumbnails ;)
554 rm -rf thumb-* index.html
558 <title>Images</title>
561 for f in *.(gif|jpeg|jpg|png)
563 convert -size 100x200 "$f" -resize 100x200 thumb-"$f"
564 echo " <a href=\"$f\"><img src=\"thumb-$f\"></a>" >> index.html
568 </html>" >> index.html
571 # unset all limits (see zshbuiltins(1) /ulimit for details)
582 # ogg2mp3 with bitrate of 192
584 oggdec -o - ${1} | lame -b 192 - ${1:r}.mp3
589 # some useful commands often hard to remember - let's grep for them {{{
592 # /usr/bin/jackd -dalsa -dhw:0 -r48000 -p1024 -n2
593 # now play audio file:
594 # alsaplayer -o jack foobar.mp3
596 # send files via netcat
598 # send() {j=$*; tar cpz ${j/%${!#}/}|nc -w 1 ${!#} 51330;}
599 # send dir* $HOST # alias receive='nc -vlp 51330 | tar xzvp'
602 # dh_make -e foo@localhost -f $1
603 # dpkg-buildpackage -rfakeroot
605 # dpkg-scanpackages ./ /dev/null | gzip > Packages.gz
606 # dpkg-scansources . | gzip > Sources.gz
607 # grep-dctrl --field Maintainer $* /var/lib/apt/lists/*
610 # convert -geometry 200x200 -interlace LINE -verbose
611 # ldapsearch -x -b "OU=Bedienstete,O=tug" -h ldap.tugraz.at sn=$1
612 # ps -ao user,pcpu,start,command
613 # gpg --keyserver blackhole.pca.dfn.de --recv-keys
614 # xterm -bg black -fg yellow -fn -misc-fixed-medium-r-normal--14-140-75-75-c-90-iso8859-15 -ah
615 # nc -vz $1 1-1024 # portscan via netcat
616 # wget --mirror --no-parent --convert-links
618 # autoload -U tetris; zle -N tetris; bindkey '...' ; echo "press ... for playing tennis"
620 ## END OF FILE #################################################################
621 # vim:foldmethod=marker