-# cd && ls
- cl() { cd $1 && ls -a }
-
-# Use vim to convert plaintext to HTML
- 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 <file>
-# 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 ;;
- *.rar) unrar $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 ;;
- *) echo "'$1' Error. Please go away" ;;
- esac
- else
- echo "'$1' is not a valid file"
- fi
- }
-
-# Usage: smartcompress <file> (<type>)
-# 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 <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
- }
-
- 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
- }
-
-# Use 'view' to read manpages, if u want colors, regex - search, ...
-# like vi(m).
-# It's shameless stolen from <http://www.vim.org/tips/tip.php?tip_id=167>
- vman() { man $* | col -b | view -c 'set ft=man nomod nolist' - }
-
-# search for various types or README file in dir and display them in $PAGER
-# function readme() { $PAGER -- (#ia3)readme* }
- readme() {
- local files
- files=(./(#i)*(read*me|lue*m(in|)ut)*(ND))
- if (($#files))
- then $PAGER $files
- else
- print 'No README files.'
- fi
- }
-
-# find all suid files in $PATH
-# suidfind() { ls -latg $path | grep '^...s' }
- suidfind() { ls -latg $path/*(sN) }
-
-# See above but this is /better/ ... anywise ..
- findsuid() {
- print 'Output will be written to ~/suid_* ...'
- $SUDO find / -type f \( -perm -4000 -o -perm -2000 \) -ls > ~/suid_suidfiles.`date "+%Y-%m-%d"`.out 2>&1
- $SUDO find / -type d \( -perm -4000 -o -perm -2000 \) -ls > ~/suid_suiddirs.`date "+%Y-%m-%d"`.out 2>&1
- $SUDO find / -type f \( -perm -2 -o -perm -20 \) -ls > ~/suid_writefiles.`date "+%Y-%m-%d"`.out 2>&1
- $SUDO find / -type d \( -perm -2 -o -perm -20 \) -ls > ~/suid_writedirs.`date "+%Y-%m-%d"`.out 2>&1
- print 'Finished'
- }
-
-# Reload functions.
- refunc() {
- for func in $argv
- do
- unfunction $func
- autoload $func
- done
- }
-
-# a small check to see which DIR is located on which server/partition.
-# stolen and modified from Sven's zshrc.forall
- dirspace() {
- for dir in $path;
- do
- (cd $dir; echo "-<$dir>"; du -shx .; echo);
- done
- }
-
-# $ show_print `cat /etc/passwd`
- slow_print() {
- for argument in "${@}"
- do
- for ((i = 1; i <= ${#1} ;i++)) {
- print -n "${argument[i]}"
- sleep 0.08
- }
- print -n " "
- done
- print ""
- }
-
- status() {
- 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: $(cat /etc/[A-Za-z]*[_-][rv]e[lr]*)"
- print "Uptime:$(uptime)"
- print ""
- }
-
- audiorip() {
- mkdir -p ~/ripps
- cd ~/ripps
- cdrdao read-cd --device $DEVICE --driver generic-mmc audiocd.toc
- cdrdao read-cddb --device $DEVICE --driver generic-mmc audiocd.toc
- echo " * Would you like to burn the cd now? (yes/no)"
- read input
- if
- [ "$input" = "yes" ]; then
- echo " ! Burning Audio CD"
- audioburn
- echo " * done."
- else
- echo " ! Invalid response."
- fi
- }
-
- audioburn() {
- cd ~/ripps
- cdrdao write --device $DEVICE --driver generic-mmc audiocd.toc
- echo " * Should I remove the temporary files? (yes/no)"
- read input
- if [ "$input" = "yes" ]; then
- echo " ! Removing Temporary Files."
- cd ~
- rm -rf ~/ripps
- echo " * done."
- else
- echo " ! Invalid response."
- fi
- }
-
- mkaudiocd() {
- cd ~/ripps
- for i in *.[Mm][Pp]3; do mv "$i" `echo $i | tr '[A-Z]' '[a-z]'`; done
- for i in *.mp3; do mv "$i" `echo $i | tr ' ' '_'`; done
- for i in *.mp3; do mpg123 -w `basename $i .mp3`.wav $i; done
- normalize -m *.wav
- for i in *.wav; do sox $i.wav -r 44100 $i.wav resample; done
- }
-
- mkiso() {
- echo " * Volume name "
- read volume
- echo " * ISO Name (ie. tmp.iso)"
- read iso
- echo " * Directory or File"
- read files
- mkisofs -o ~/$iso -A $volume -allow-multidot -J -R -iso-level 3 -V $volume -R $files
- }
-
-# generate thumbnails ;)
- genthumbs () {
- rm -rf thumb-* index.html
- echo "
-<html>
- <head>
- <title>Images</title>
- </head>
- <body>" > index.html
- for f in *.(gif|jpeg|jpg|png)
- do
- convert -size 100x200 "$f" -resize 100x200 thumb-"$f"
- echo " <a href=\"$f\"><img src=\"thumb-$f\"></a>" >> index.html
- done
- echo "
- </body>
-</html>" >> index.html
- }
-
-# unset all limits (see zshbuiltins(1) /ulimit for details)
- allulimit() {
- ulimit -c unlimited
- ulimit -d unlimited
- ulimit -f unlimited
- ulimit -l unlimited
- ulimit -n unlimited
- ulimit -s unlimited
- ulimit -t unlimited
- }
-
-# ogg2mp3 with bitrate of 192
- ogg2mp3_192() {
- oggdec -o - ${1} | lame -b 192 - ${1:r}.mp3
- }
-
-# RFC 2396 URL encoding in Z-Shell
- urlencode() {
- setopt localoptions extendedglob
- input=( ${(s::)1} )
- print ${(j::)input/(#b)([^A-Za-z0-9_.!~*\'\(\)-])/%$(([##16]#match))}
- }
-
-# get x-lite voip software
- getxlite() {
- setopt local_options
- setopt errreturn
- [ -d ~/tmp ] || mkdir ~/tmp
- cd ~/tmp
- echo "Downloading http://www.counterpath.com/download/X-Lite_Install.tar.gz and storing it in ~/tmp:"
- if wget http://www.counterpath.com/download/X-Lite_Install.tar.gz ; then
- unp X-Lite_Install.tar.gz && echo done || echo failed
- else
- echo "Error while downloading." ; return 1
- fi
- if [ -x xten-xlite/xtensoftphone ] ; then
- echo "Execute xten-xlite/xtensoftphone to start xlite."
- fi
- }
-
-# get skype
- getskype() {
- setopt local_options
- setopt errreturn
- echo "Downloading debian package of skype."
- echo "Notice: If you want to use a more recent skype version run 'getskypebeta'."
- wget http://www.skype.com/go/getskype-linux-deb
- $SUDO dpkg -i skype_debian-*.deb && echo "skype installed."
- }
-
-# get beta-version of skype
- getskypebeta() {
- setopt local_options
- setopt errreturn
- echo "Downloading debian package of skype (beta version)."
- wget http://www.skype.com/go/getskype-linux-beta-deb
- $SUDO dpkg -i skype-beta*.deb && echo "skype installed."
- }
-
-# get gzimo (VoIP software)
- getgizmo() {
- setopt local_options
- setopt errreturn
- echo "gconf2-common and libgconf2-4 have to be available. Installing therefor."
- $SUDO apt-get update
- $SUDO apt-get install gconf2-common libgconf2-4
- wget $(lynx --dump http://www.gizmoproject.com/download-linux.html | awk '/\.deb/ {print $2" "}' | tr -d '\n')
- $SUDO dpkg -i libsipphoneapi*.deb bonjour_*.deb gizmo-*.deb && echo "gizmo installed."
- }
-
-# get AIR - Automated Image and Restore
- getair() {
- setopt local_options
- setopt errreturn
- [ -w . ] || { echo 'Error: you do not have write permissions in this directory. Exiting.' ; return 1 }
- local VER='1.2.8'
- wget http://puzzle.dl.sourceforge.net/sourceforge/air-imager/air-$VER.tar.gz
- tar zxf air-$VER.tar.gz
- cd air-$VER
- INTERACTIVE=no $SUDO ./install-air-1.2.8
- [ -x /usr/local/bin/air ] && [ -n "$DISPLAY" ] && $SUDO air
- }
-
-# get specific git commitdiff
- git-get-diff() {
- if [ -z $GITTREE ] ; then
- GITTREE='linux/kernel/git/torvalds/linux-2.6.git'
- fi
- if ! [ -z $1 ] ; then
- ${=BROWSER} "http://kernel.org/git/?p=$GITTREE;a=commitdiff;h=$1"
- else
- echo "Usage: git-get-diff <commit>"
- fi
- }
-
-# get specific git commit
- git-get-commit() {
- if [ -z $GITTREE ] ; then
- GITTREE='linux/kernel/git/torvalds/linux-2.6.git'
- fi
- if ! [ -z $1 ] ; then
- ${=BROWSER} "http://kernel.org/git/?p=$GITTREE;a=commit;h=$1"
- else
- echo "Usage: git-get-commit <commit>"
- fi
- }
-
-# get specific git diff
- git-get-plaindiff() {
- if [ -z $GITTREE ] ; then
- GITTREE='linux/kernel/git/torvalds/linux-2.6.git'
- fi
- if ! [ -z $1 ] ; then
- wget "http://kernel.org/git/?p=$GITTREE;a=commitdiff_plain;h=$1" -O $1.diff
- else
- echo 'Usage: git-get-plaindiff '
- fi
- }
-
-# log 'make install' output
-# http://strcat.de/blog/index.php?/archives/335-Software-sauber-deinstallieren...html
- mmake() {
- [[ ! -d ~/.errorlogs ]] && mkdir ~/.errorlogs
- =make -n install > ~/.errorlogs/${PWD##*/}-makelog
- }
-
-# indent source code
- smart-indent() {
- indent -npro -kr -i8 -ts8 -sob -l80 -ss -ncs $*
- }
-
-# highlight important stuff in diff output, usage example: hg diff | hidiff
- [ -x =histring ] && \
- alias hidiff="histring -fE '^Comparing files .*|^diff .*' | histring -c yellow -fE '^\-.*' | histring -c green -fE '^\+.*'"
-
-# rename pictures based on information found in exif headers
- exirename() {
- if [ $# -lt 1 ] ; then
- echo 'Usage: jpgrename $FILES' >& 2
- return 1
- else
- echo -n 'Checking for jhead with version newer than 1.9: '
- jhead_version=`jhead -h | grep 'used by most Digital Cameras. v.*' | awk '{print $6}' | tr -d v`
- if [[ $jhead_version > '1.9' ]]; then
- echo 'success - now running jhead.'
- jhead -n%Y-%m-%d_%Hh%M_%f $*
- else
- echo 'failed - exiting.'
- fi
- fi
- }
-# }}}
-
-# mercurial related stuff {{{
- if type -p hg >/dev/null 2>&1 ; then
- # gnu like diff for mercurial
- # http://www.selenic.com/mercurial/wiki/index.cgi/TipsAndTricks
- hgdi() {
- for i in `hg status -marn "$@"` ; diff -ubwd <(hg cat "$i") "$i"
- }
-
- # build debian package
- alias hbp='hg-buildpackage'
-
- # diffstat for specific version of a mercurial repository
- # hgstat => display diffstat between last revision and tip
- # hgstat 1234 => display diffstat between revision 1234 and tip
- hgstat() {
- [ -n "$1" ] && hg diff -r $1 -r tip | diffstat || hg export tip | diffstat
- }
-
- # get current mercurial tip via hg itself
- gethgclone() {
- setopt local_options
- setopt errreturn
- if [ -f mercurial-tree/.hg ] ; then
- cd mercurial-tree
- echo "Running hg pull for retreiving latest version..."
- hg pull
- echo "Finished update. Building mercurial"
- make local
- echo "Setting \$PATH to $PWD:\$PATH..."
- export PATH="$PWD:$PATH"
- else
- echo "Downloading mercurial via hg"
- hg clone http://selenic.com/repo/hg mercurial-tree
- cd mercurial-tree
- echo "Building mercurial"
- make local
- echo "Setting \$PATH to $PWD:\$PATH..."
- export PATH="$PWD:$PATH"
- echo "make sure you set it permanent via ~/.zshrc if you plan to use it permanently."
- # echo "Setting \$PYTHONPATH to PYTHONPATH=\${HOME}/lib/python,"
- # export PYTHONPATH=${HOME}/lib/python
- fi
- }
-
- fi # end of check whether we have the 'hg'-executable
-
- # get current mercurial snapshot
- gethgsnap() {
- setopt local_options
- setopt errreturn
- if [ -f mercurial-snapshot.tar.gz ] ; then
- echo "mercurial-snapshot.tar.gz exists already, skipping download."
- else
- echo "Downloading mercurial snapshot"
- wget http://www.selenic.com/mercurial/mercurial-snapshot.tar.gz
- fi
- echo "Unpacking mercurial-snapshot.tar.gz"
- tar zxf mercurial-snapshot.tar.gz
- cd mercurial-snapshot/
- echo "Installing required build-dependencies"
- $SUDO apt-get update
- $SUDO apt-get install python2.4-dev
- echo "Building mercurial"
- make local
- echo "Setting \$PATH to $PWD:\$PATH..."
- export PATH="$PWD:$PATH"
- echo "make sure you set it permanent via ~/.zshrc if you plan to use it permanently."
- }
-# }}}
-
-# some useful commands often hard to remember - let's grep for them {{{
-
-# Work around ion/xterm resize bug.
-#if [ "$SHLVL" = 1 ]; then
-# if [ -x `which resize 2>/dev/null` ]; then
-# eval `resize </dev/null`
-# fi