#!/bin/env zsh #colored messages sh_coloroff() { echo -en "$reset_color" } sh_colormsg() { [ -n "$1" ] && echo -en "${fg_bold[white]}${@}${reset_color}" } sh_error() { echo -e "${fg_bold[red]}[ e ]${reset_color} $@" } sh_info() { echo -e "${fg_bold[yellow]}[ i ]${reset_color} $@" } sh_success() { echo -e "${fg_bold[green]}[ k ]${reset_color} $@" } sh_mesg() { echo -e "${fg_bold[cyan]}[ m ]${reset_color} $@" } # develop helpers alias sh_indent='indent -nsaf -npcs -cli2 -i2 -lp -nprs -nsaw -nut -cbi2 -bli0 -bls -nbad -npsl' alias sh_diff='diff -abBpur' alias sh_svnstat="svn status | awk '/^[^?]/'" # use with svn diff -r `sh_svnprev` sh_svnprev() { echo $(( `svnversion . | sed 's/[^0-9].*//'` - 1)) } # $1 - path sh_fcore() { p="." [ -n "$1" ] && p="$1" find $p -name "core\.*[[:digit:]]*" -type f 2>& /dev/null return 0 } # # change to a profile written down in $HOME/.myprofiles # # #begin[NAME] # FOO=BAR # JOHN=DOE # #end[NAME] # # $1 - name of the profile (a must) # $2 - name of the profilefile (optional) sh_myprofile() { f=$HOME/.myprofiles [ -n "$1" ] || return 1 [ -n "$2" ] && f="$2" sh_info "setting profiles to \"$1\" ... " sed -n '/^#begin\['$1'\]/,/^#end\['$1'\]/p' "$f" | while read l do eval $l done sh_success "done" } alias osd='osd_cat -c white -o 20 -l 30' # mplayer alias mplayer='mplayer -menu -aop list=volnorm' alias mmplayer='mplayer -nosound' alias lmplayer='mplayer -loop 0' alias mplayerc='mplayer /mnt/cdrom/*' alias mplayerd='mplayer /mnt/dvd/*' alias dvdplayer='mplayer -dvd 1 -dvd-device /dev/cdroms/cdrom1' alias gdvdplayer='gmplayer -dvd 1 -dvd-device /dev/cdroms/cdrom1' # use last download wallpaper alias show_latestwp='fbsetbg -f $HOME/.backgrounds/`ls -1t $HOME/.backgrounds/ | head -n 1`' alias ws="xprop -root | awk '/_WIN_WORKSPACE\(/ {print \$3}' | osd_cat -c white -f -*-lucida-medium-r-*-*-20-*-*-*-*-*-*-* -o 20 -p top -A center" dubigf() { du -sh * | awk '/[[:space:]]*[[:digit:]]+,*[[:digit:]]*G/' | sort -nr du -sh * | awk '/[[:space:]]*[[:digit:]]+,*[[:digit:]]*M/' | sort -nr } sh_create_mail_dir() { [ -n "$1" ] && mkdir --parent $1/cur $1/tmp $1/new } sh_pingip() { ping -c 1 "$1" | \ sed 's/^PING.* (\(.*\.[[:digit:]]\+\)).*$/\1/;q' } if which nmap 2>&1 > /dev/null; then # check hosts that are online sh_whoisonline() { if [ -n "$1" ]; then net="$1" else net=$(grep `hostname` /etc/hosts | awk -F '.' '{ print $1"."$2"."$3".0/24"}') fi sh_info "testing $net for online boxes" sudo nmap -sP $net | awk '/Host/ && /up/ { print $0; }' sh_success "done" } fi sh_ed2k() { wget -q -O - "$1" | grep "ed2k://" | sed -e 's/^.*=//g;s/..$//g' } sh_fakepass() { local l=8 [ -n "$1" ] && l=$1 dd if=/dev/urandom count=1 2> /dev/null | uuencode -m - | head -n 2 | tail -n 1 | cut -c -$l } alias sh_fakename='nc koeln.ccc.de 23 | cut -d \ -f 4,5' sh_noisetimer() { sounds=( $HOME/.sounds/lightning.ogg \ $HOME/.sounds/ring.ogg ) s=$sounds[$((1 + $(($RANDOM % 2)) ))] case $# in 0 );; 1 ) ( echo "mplayer $s >& /dev/null \n" ) | at $1 >& /dev/null sh_info "ok, noise in $1" ;; * ) t=$1; shift 1 ( echo "mplayer $s >& /dev/null \nxmessage -display $DISPLAY -nearmouse -timeout 10 $*" ) | \ at $t >& /dev/null sh_info "ok, noise in $t" ;; esac } tarcp() { if (( $# >= 2 )); then echo "copy ${@[1, -2]} => ${@[-1]}" # http://www.ivarch.com/programs/pv.shtml if which pv ; then tar -c -f - ${@[1, -2]} | pv -t -b -r | tar -x -f - -C ${@[-1]} else tar -c -v -f - ${@[1, -2]} | tar -x -f - -C ${@[-1]} fi else "error, not enough parameters." return 1 fi } # dict wordnet wn() { dict -d wn $@ }