###-------------------------------------------------- ### Funktionen # Show the path from a symlink to its ultimate source. folsym() { if [[ -e $1 || -h $1 ]]; then file=$1 else file=`which $1` fi if [[ -e $file || -L $file ]]; then if [[ -L $file ]]; then echo `ls -ld $file | perl -ane 'print $F[7]'` '->' folsym `perl -le '$file = $ARGV[0]; $dest = readlink $file; if ($dest !~ m{^/}) { $file =~ s{(/?)[^/]*$}{$1$dest}; } else { $file = $dest; } $file =~ s{/{2,}}{/}g; while ($file =~ s{[^/]+/\.\./}{}) { ; } $file =~ s{^(/\.\.)+}{}; print $file' $file` else ls -d $file fi else echo $file fi } # mkdir && cd function mcd() { mkdir "$@"; cd "$@" } # cd && ls function cl() { cd $1 && ls -a } # Display current directory as a 'tree'. # Nice replacement would be: http://strcat.neessen.net/hacks/tree function tree() { find . | sed -e 's/[^\/]*\//|----/g' -e 's/---- |/ |/g' | $PAGER } ll() { ls -la --color=auto "$@" | more } .() { if [[ $# -eq 0 ]]; then cd $OLDPWD else builtin . $* fi } 2html() { vim -u NONE -n -c ':syntax on' -c ':so $VIMRUNTIME/syntax/2html.vim' -c ':wqa' $1 > /dev/null 2> /dev/null } # Usage: simple-extract # Description: extracts archived files (maybe) simple-extract () { if [[ -f "$1" ]] then case "$1" in *.tar.bz2) bzip2 -v -d "$1" ;; *.tar.gz) tar -xvzf "$1" ;; *.ace) unace e "$1" ;; *.rar) unrar x "$1" ;; *.deb) ar -x "$1" ;; *.bz2) bzip2 -d "$1" ;; *.lzh) lha x "$1" ;; *.gz) gunzip -d "$1" ;; *.tar) tar -xvf "$1" ;; *.tgz) gunzip -d "$1" ;; *.tbz2) tar -jxvf "$1" ;; *.zip) unzip "$1" ;; *.Z) uncompress "$1" ;; *.shar) sh "$1" ;; *) echo "'"$1"' Error. Please go away" ;; esac else echo "'"$1"' is not a valid file" fi } # Usage: smartcompress () # Description: compresses files or a directory. Defaults to tar.gz smartcompress() { if [ '$2' ]; then case '$2' in tgz | tar.gz) tar -zcvf$1.$2 '$1' ;; tbz2 | tar.bz2) tar -jcvf$1.$2 '$1' ;; tar.Z) tar -Zcvf$1.$2 '$1' ;; tar) tar -cvf$1.$2 '$1' ;; gz | gzip) gzip '$1' ;; bz2 | bzip2) bzip2 '$1' ;; *) echo "Error: $2 is not a valid compression type" ;; esac else smartcompress '$1' tar.gz fi } # Usage: show-archive # Description: view archive without unpack show-archive() { if [[ -f $1 ]] then case $1 in *.tar.gz) gunzip -c $1 | tar -tf - -- ;; *.tar) tar -tf $1 ;; *.tgz) tar -ztf $1 ;; *.zip) unzip -l $1 ;; *.bz2) bzless $1 ;; *) echo "'$1' Error. Please go away" ;; esac else echo "'$1' is not a valid archive" fi } function vman() { man $* | col -b | view -c 'set ft=man nomod nolist' - } # Quick&dirty hack to read heise-news ( function heise() { CURDIR=${pwd}; cd /tmp; if [[ -s tmp/heise.rdf ]] then rm heise.rdf fi wget -q -O - http://heise.de/newsticker/heise.rdf |\ sed -e '/title/!d;s, \(.*\),\1,' -e '/heise online/d' ; cd $CURDIR } # search for various types or README file in dir and display them in $PAGER # function readme() { $PAGER -- (#ia3)readme* } function readme() { local files files=(./(#i)*(read*me|lue*m(in|)ut)*(ND)) if (($#files)) then $PAGER $files else print 'No README files.' fi } # if [ Now-Playing == "relaxmusic" ];then .. ;-) beer() { echo " _.._..,_,_" echo " ( )" echo " ]~,\"-.-~~[" echo " .=])' (; ([ Cheers!" echo " | ]:: ' [" echo " '=]): .) ([" echo " |:: ' |" echo " ~~----~~" } # Add directory to a bookmark-list # % bmadd # add directory to bookmark list # % bmls # show list of bookmark list # % bmvi # edit bookmark list # % bm $NUMBER # change directory to $NUMBER bookmark BMRC=~/.bmrc touch $BMRC bmls() { cat $BMRC | sort -n} bmvi() { vi $BMRC } bmadd() { local bmdir=`pwd` local newid=$1 local bmname='' for bmname in `bm_path_list` do if [ "$bmname" = "$bmdir" ]; then echo "$bmdir is already in bm list" return fi done if [ -z $newid ]; then maxid=`cat $BMRC | cut -f 1 | sort -n -r | head -1` if [ "$maxid" -ge 1 ]; then newid=`expr 0$maxid + 1` else newid=1 fi fi echo "$newid\t$bmdir" >> $BMRC } bm() { local num=$1 local bmdir=`bm_get $num` if [ -z "$bmdir" ]; then bmls [ -z "$num" ] || echo "$num is not in bm list" return fi cd "$bmdir" } bm_get() { local bmdir=`cat $BMRC | egrep "^${1}[[:space:]]" | cut -f 2` echo $bmdir } bm_path_list() { cut -f 2 < $BMRC } # display some informations function sstatus() { # I must use this because i use this function on different # systems if [ "${OS}" = "openbsd" ]; then local system="$(uname -sr)" else if [ $(which crux) ]; then local system="$(crux)" else local system="$(cat /etc/[A-Za-z]*[_-][rv]e[lr]*)" fi fi print "" print "Date..: "$(date "+%Y-%m-%d %H:%M:%S")"" print "Shell.: Zsh $ZSH_VERSION (PID = $$, $SHLVL nests)" print "Term..: $TTY ($TERM), $BAUD bauds, $COLUMNS x $LINES cars" print "Login.: $LOGNAME (UID = $EUID) on $HOST" print "System: $system" print "Uptime:$(uptime)" print "" } # generate thumbnails ;) function genthumbs () { rm -rf thumb-* index.html echo " Images " > index.html for f in *.(gif|jpeg|jpg|png) do convert -size 100x200 "$f" -resize 100x200 thumb-"$f" echo " " >> index.html done echo " " >> index.html } # gpg function sgpg { gpg --keyserver pgp.mit.edu --search-key "$1"; } # Process search function psgrep { ps ax | grep $1 | fgrep -v "grep $1" } ## recompile it. src () { autoload -U zrecompile [ -f ~/.zshrc ] && zrecompile -p ~/.zshrc [ -f ~/.zcompdump ] && zrecompile -p ~/.zcompdump [ -f ~/.zshrc.zwc.old ] && rm -f ~/.zshrc.zwc.old [ -f ~/.zcompdump.zwc.old ] && rm -f ~/.zcompdump.zwc.old source ~/.zshrc } # Exchange ' ' for '_' in filenames. unspaceit() { for _spaced in "${@:+"$@"}"; do if [ ! -f "${_spaced}" ]; then continue; fi _underscored=$(echo ${_spaced} | tr ' ' '_'); if [ "${_underscored}" != "${_spaced}" ]; then mv "${_spaced}" "${_underscored}"; fi done } # Searching for keyword(s) # $ google foobar # $ google "foobar 42" # $ google "foobar " # $ google foo+bar+42 function google () { firefox "http://www.google.com/search?q="$1""; } # Searching for keywords in Newsgroups # $ ggogle foobar function ggogle () { firefox "http://groups.google.com/groups?q="$1""; } # Search for Posting from # $ mggogle "2003-07-01T15-17-41@bofh.my-fqdn.de" function mggogle () { firefox "http://groups.google.com/groups?selm="$1"" ; } # Search Postings from # $ agoogle "John J. Rambo" # $ agoogle strcat@gmx.net function agoogle () { firefox "http://groups.google.com/groups?as_uauthors="$1"" ; } # look for definitions function wpedia () { BROWSER="firefox" JARGON_URL="http://de.wikipedia.org/wiki" for i in ${*}; do ${BROWSER} ${JARGON_URL}/${i} done } # show rfc function rfc () { BROWSER="firefox" JARGON_URL="http://www.ietf.org/rfc" for i in ${*}; do ${BROWSER} ${JARGON_URL}/rfc${i}.txt done } # A quick globbing reference, stolen from GRML. help-glob() { echo -e " / directories . plain files @ symbolic links = sockets p named pipes (FIFOs) * executable plain files (0100) % device files (character or block special) %b block special files %c character special files r owner-readable files (0400) w owner-writable files (0200) x owner-executable files (0100) A group-readable files (0040) I group-writable files (0020) E group-executable files (0010) R world-readable files (0004) W world-writable files (0002) X world-executable files (0001) s setuid files (04000) S setgid files (02000) t files with the sticky bit (01000) print *(m-1) # Dateien, die vor bis zu einem Tag modifiziert wurden. print *(a1) # Dateien, auf die vor einem Tag zugegriffen wurde. print *(@) # Nur Links print *(Lk+50) # Dateien die ueber 50 Kilobytes grosz sind print *(Lk-50) # Dateien die kleiner als 50 Kilobytes sind print **/*.c # Alle *.c - Dateien unterhalb von \$PWD print **/*.c~file.c # Alle *.c - Dateien, aber nicht 'file.c' print (foo|bar).* # Alle Dateien mit 'foo' und / oder 'bar' am Anfang print *~*.* # Nur Dateien ohne '.' in Namen chmod 644 *(.^x) # make all non-executable files publically readable print -l *(.c|.h) # Nur Dateien mit dem Suffix '.c' und / oder '.h' print **/*(g:users:) # Alle Dateien/Verzeichnisse der Gruppe >users< echo /proc/*/cwd(:h:t:s/self//) # Analog zu >ps ax | awk '{print $1}'<" } # Übersetzung bei dict.leo.org leo() { w3m "http://dict.leo.org/?search=$*" } ###################################################################### # so ein Papierkorb ist was Feines # wenn er funktionier ;) # TRASH=~/.trash alias 'mttrash'='rm -f ~/.trash/*' function trash() { [[ -z ${TRASH} ]] && print "No ${TRASH} defined." && return 1 [[ ! -d ${TRASH} ]] && mkdir ${TRASH} mv $* ${TRASH} }