#!/bin/sh

# user specific aliases and functions.
# include this file with :  ~/.alias in your ~/.bashrc .
# assumes : shopt -s expand_aliases
# _____________________________________________________
# $Date: 2008-11-01 10:58:27 +0100 (Sat, 01 Nov 2008) $
# -----------------------------------------------------
#        \   ^__^
#         \  (oo)\_______
#            (__)\       )\/\
#                ||----w |
#                ||     ||

# This file is sourced by all *interactive* bash shells on startup.  This
# file should generate *no output* upon execution, or it will break the scp and rcp commands.

# The shopt builtin alias expansion
shopt -s expand_aliases

# specification of the directory colouring file
##eval `dircolors -b /etc/DIR_COLORS`

#alias fbi='/usr/bin/fbi'
#alias fbi='/usr/local/bin/fbi'

# Coloured output, if available (this can be checked with ls --help | grep ... )
alias d="ls --color"
#[ "$TERM" == "linux" ] && (
[ "`uname`" == "Linux" ] && { alias ls="ls --color=auto" ; alias ll="ls --color -l" ;  alias grep='grep --colour' ; alias chown='chown -c' ; alias chmod='chmod -c' ; }
alias ll='ls -l'
alias dl='ll'

# Audio signaling
alias buzz='ls -R / > /dev/dsp; cat /dev/urandom > /dev/dsp'
alias beep='last | tail -n 100 > /dev/dsp'
#alias beep='echo -en "\033[10;1729]\a"'

#alias umount=umount + eject ...
alias l='ls'
alias lr='ls -R'
alias llr='ll -R'
alias rmfRd='rm -fRd'

# mispellings
alias les='less'
alias less='less -i'

# silent octave and gdb
alias octave='octave -q'
alias gdb='gdb -q'

alias nautilus='nautilus --browser'

# a nice quick reminder
alias readme.here='$EDITOR ./readme'

# quick flatbed scanner commands, to be piped in a file or fim imag viewer
alias scan.a4='scanimage -l0mm -t0mm -x210mm -y300mm --depth 32 --resolution 100 --format=tiff'
alias scan.a5='scanimage -l0mm -t0mm -x150mm -y210mm --depth 32 --resolution 100 --format=tiff'

# usb stick pen commands
alias mountcam='( until mount $PEN ; do sleep 0.5 ;  umount $PEN > /dev/null 2>&1 ; done ; ls $PEN ; )'
alias mountcamb='( until mount $PENB ; do sleep 0.5 ;  umount $PENB > /dev/null 2>&1 ; done ; ls $PENB ; )'
alias umountcam='umount $PEN;sync'
alias umountcamb='umount $PENB;sync'

alias vimt='vim -t tags'

alias htmltidy='tidy'

# builds an html list of files in the current dir
HTMLLISTREXP='s/\(.*$\)/<a href="\1">\1<\/a>\n<br\/>/g'
alias hlist='find * | sort | sed "$HTMLLISTREXP"'
# the same, a little better
function hfind(){ find $@ | sort | perl -e 'while(<>){print "<p><a href=\"$_\">$_</a></p/>";}';}

# custom date aliases
alias date.ymd='date +%Y%m%d'
alias date.dez='date.ymd'
alias date.ymdh='date +%Y%m%d@%k'

# i am too lazy to type something longer to halting my machine
alias 0='sudo poweroff'
alias 00='mkill;offline;sleep 1;reboot'

# sometimes there is the need killing mutt, systemwide or in the current tty
alias kmutt='kill -9 `pidof mutt`'
alias kmutthere="kill -9  `ps | grep mutt | sed s/' .*'//`"
alias kmsmtp='kill -9 `pidof msmtp`'

#alias rm='rm -i'
#alias cp='cp -i'
#alias mv='mv -i'

alias battery='cat /proc/acpi/battery/BAT1/state'
alias cam='sync;mountcam'
alias camb='sync;mountcamb'
alias ucam='umountcam'
alias ucamb='umountcamb'
alias aliasfile='$EDITOR ~/.alias'
alias aliasfile_private='$EDITOR ~/.alias_private'
alias isyncfile='$EDITOR ~/.isync'
alias bashrc='$EDITOR ~/.bashrc'
alias vimrc=' $EDITOR ~/.vimrc'
alias fimrc=' $EDITOR ~/.fimrc'

function tell()
{
        # flite (festival lite) is a speech synthetizer
        FILE=$HOME/.tmp/speech
        [ "$#" == "1" ] && ( echo "$@" > $FILE )
        [ "$#" != "1" ] && ( cat > $FILE )
        [ -f $FILE ] && flite $FILE && [ -f $FILE ] && rm    $FILE 
}
function tell2()
{
        # flite (festival lite) is a speech synthetizer
        local TMPDIR="/tmp";

        [ "$#" == "0" ] && cat > $TMPDIR/speech;
        [ "$#" != "0" ] && echo $@ > $TMPDIR/speech;

        flite $TMPDIR/speech;
        rm    $TMPDIR/speech;
}

function venceslao()
{
        [ "$1" == "-h" ] && tell "Hello, I am Venceslao, and I am your personal digital speaker\n"
}

function sing()
{
        TMPDIR="/tmp"
        [ "$#" == "0" ] && ( cat > $TMPDIR/sing )
        [ "$#" != 1 ] && echo -E $@ > $TMPDIR/sing
        #mp3blaster $TMPDIR/speech
        echo ciao
        cat $TMPDIR/sing
        rm    $TMPDIR/sing
}

# say you want to repeat a snipped of shell forever; e.g.: ssh host -t screen -x
function whilesleep() { local N=$1; shift ; while [ 1 ] ; do eval $@   ; sleep $N ;  done  }
alias ws='whilesleep 1'

alias whilesleep1='whilesleep 1'
alias whilesleep5='whilesleep 5'
alias whilesleep10='whilesleep 10'

alias u='cd ..'
alias uu='cd ../..'
alias uuu='cd ../../..'

#alias ej='eject /dev/cdrom'
alias ej='eject /mnt/cdrom;read;eject -t /mnt/cdrom'
alias ej1='eject /mnt/cdrom1;read;eject -t /mnt/cdrom1'

alias mount.cd='mount /mnt/cdrom'
alias umount.cd='umount /mnt/cdrom; eject /dev/cdrom'

# music finder script
alias music='mf.sh'

# are we under X ?
alias xrunning='[ "$DISPLAY" != "" ]'
alias mplayer.fbdev='mplayer   -vf scale=1024:768  -vo fbdev2'
alias mplayer.fb='mplayer -vf scale=800:600 -vo fbdev'
alias mplayer.fs='mplayer -vf scale=1024:768 -fs'
    
#alias fb='fbgs.sh -a'
alias fb='fimgs -a'

#a quick way to visualize files :)
function view()
{
        [ "$#" -eq "0" ] && view .
        for i in "$@"
        do
                [ -d "$i" ] && du -s "$i" && ls -l "$i"
                [[ "$i" =~ \\.pdf$ ]] && fb "$i"
#               [[ "$i" =~ \\.pdf$ ]] && pdftotext "$i"
#               [[ "$i" =~ \\.ps$  ]] && ps2ascii"$i"
                [[ "$i" =~ \\.\(jpeg\|jpg\|\png\|gif\|bmp\|tiff\)$ ]] &&  ( ( xrunning && kuickshow "$i" ) || fbi -a "$i" )
                [[ "$i" =~ \\.\(mp3\|ogg\)$ ]] && mp3tag "$i"
                [[ "$i" =~ \\.\(mpg\|avi\)$ ]] && file "$i"
                [[ "$i" =~ \\.tar$ ]] && tar -tf "$i"
                [[ "$i" =~ \\.tgz$ ]] && tar -tzf "$i"
                [[ "$i" =~ \\.tar.gz$ ]] && tar -tzf -v "$i" 
                [[ "$i" =~ \\.\(txt\|c\|h\|html\|nfo\|conf\|log\|s\|asm\)$ ]] && less "$i"
        done
}

#alias freeze='echo "You must be superuser to put the system into FREEZE state:" && su -c "echo 4 > /proc/acpi/sleep"'
# no: alias freeze='echo "You must be superuser to put the system into FREEZE state:" && su -c "echo 4 > /sys/power/state"'
#alias freeze="SHUTDOWN_COMMAND='echo shutdown > /sys/power/disk ; echo disk > /sys/power/state'; [[ \"$UID\" == 0 ]] && ( $SHUTDOWN_COMMAND ;  ) "
alias freeze="echo shutdown > /sys/power/disk ; echo disk > /sys/power/state "
#alias grepips='grep "[(][[:alnum:]]\{1,3\}""[[:alnum:]]\{1,3\}" -'
alias grepips="grep '[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+'"
alias sedips_nl="sed 's/\([0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+\)/\n\1\n/g'"
#alias sedips="sed 's/.*\([0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+\).*/\1/g'"
alias v='view'

function mucca(){       cowsay "$@" ;         tell    "$@" ; }
function cowsayrev(){   [ "$#" == "0" ] && cat|cowsay|tac; [ "$#" != "0" ] && echo $@|tac|rev|cowsay|tac ; }
function cowsaysim(){   [ "$#" == "0" ] && cat | cowsay | tac ; [ "$#" != "0" ] && cowsay $@ && echo "$@" | cowsayrev ; }

function drawascii(){ FILE="/tmp/text.gif" && [ "$#" != "0" ] && ( echo -E "$@" | text2gif -q > $FILE ) && [ -f $FILE ] && 
asciiview "$FILE"; }

# renders a gif image of a text string and displays it in the framebuffer
function draw(){ FILE="/tmp/text.gif" && [ "$#" != "0" ] && ( echo -E "$@" | text2gif -q > $FILE ) && [ -f $FILE ] && echo ok
ls -l  "$FILE" 
GFILE="${FILE/.gif/.png}"
convert "$FILE"  "$GFILE"
fim "$GFILE"
#&& [ -f $FILE ] && rm    $FILE ;
}

function draw2(){ FILE="/tmp/text.gif" && [ "$#" != "0" ] && ( echo -E "$@" | text2gif -q > $FILE ) && [ -f $FILE ] && 
echo ok
ls -l  "$FILE" 
GFILE="${FILE/.gif/.png}"
convert "$FILE"  "$GFILE"
fim -c 'sleep 1 ; quit' "$GFILE" 
#&& [ -f $FILE ] && rm    $FILE ;
}

alias draw.date='draw `date`'
alias draw.date='draw2 `date`'

alias consolescreensaver='date;draw.date;date'

# lazy fingers
alias j='jobs'
alias refresh.rc='( . ~/.alias ; ~/.bashrc ) || echo "There are problems in your .bashrc and .alias."'
function dusorted { ( ( [ "$#" == "0" ] && du -sS -b * ) || du -sS -b $@ ) | sort -nr ; }

alias fbgs='fbgs.sh'
alias muttrc='$EDITOR ~/.muttrc'
alias aliasrefresh='. ~/.alias'

# googling a lot ?
#function google() { local SE='http://www.google.com/search?q=';local BROWSER='links';local ARGS=`echo "$@"|sed s/' '/'+'/g;`;$BROWSER "$SE$ARGS";}
function egoogle() { local SE='http://www.google.com/search?q=';local BROWSER='links';local ARGS=`echo "$@"|sed s/' '/'+'/g;`;echo "$SE$ARGS";}
function google() { local BROWSER='links'; $BROWSER "`egoogle $@`"; }
#function googlee() { local SE='http://www.google.com/search?q=';local BROWSER='links';local ARGS=`echo "$@"|sed s/' '/+/g;`;echo "$SE$ARGS";}
function jeeves() { local SE='http://it.ask.com/web?q=';local BROWSER='links';local ARGS=`echo "$@"|sed s/' '/+/g;`;$BROWSER $SE$ARGS;}
function altavista() { local SE='http://www.altavista.com/web/results?q=';local BROWSER='links';local ARGS=`echo "$@"|sed s/' '/+/g;`;$BROWSER $SE$ARGS;}
alias search='google'

function fontiterate() { declare -a local fs ; local n=0 ; cd /usr/share/consolefonts/ ; for f in * ; do f=${f//.gz/} ; fs[$n]=$f ; ((++n)) ; done ; ((--n)) ;  
dim=$n
inc=1
n=0
echo "now press enter until you find a nice font, or press something prior to enter to cycle backwards.."
while read i
do
        echo $n : ${fs[$n]} :
        setfont ${fs[$n]}  > /dev/null 2>&1
        [[ $i != ''  ]] && ((inc*=-1)) && echo inverting direction.. press something prior to enter to reenvert again the direction
        ((n=((n+inc+dim)%dim)))
done

}


function asciiview() { ( for i in $@ ; do ( ( anytopnm $i | pnmscale -xysize $COLUMNS $((2*LINES)) | ppmtopgm | pgmtopbm | pbmtoascii -1x2 ) 2>&1 ); done ) }
alias kernelinstall='cp /usr/src/linux/System.map /boot/ && cp /boot/bzImage.gentoo /boot/bzImage.gentoo.bak && cp /usr/src/linux/arch/i386/boot/bzImage /boot/bzImage.gentoo'
alias kernelinstall.16='cp /usr/src/linux/System.map /boot/ && cp /boot/bzImage.16 /boot/bzImage.16.bak && cp /usr/src/linux/arch/i386/boot/bzImage /boot/bzImage.16'

alias god='nice -n 19 uuencode - < /dev/urandom | tr \\\n -'
alias dio='god'
alias chomp="( perl -e 'while(<STDIN>){chomp;print(\$_);};')"
#alias chomp='sed s/\\b/\\n/g'

function daterename() { for f in $@ ; do d=`date.ymd -r "$f"` ; [ ! -f "$d.$f" ] && mv "$f" "$d.$f" ; done ; }
alias renamedate=daterename

alias R='R -q'
function pdfpages(){ local PAGES=`( for i in "$@" ; do pdfinfo "$i" ; done  ) | grep Pages  | sed 's/Pages://g' | sed s/' '//g` ; 
( SUM=0; for i in  $PAGES ;do ((SUM+=$i)) ; done ; echo "sum($PAGES)"=$SUM ) }

alias sedbasename="sed 's/\(.*\/\)*//g'"
function pdfgrep() { file="$1" ; shift ; ( pdftotext "$file" - | grep $@ ) }
function wordsort() { ( cat $@ | sed 's/\b/\n/g'  | sort  | uniq | grep -v '^ *$'  ) }
function wordrank() { ( cat $@ | sed 's/\b/\n/g'  | sort  | uniq -c | grep -v '^ *$' | sort -n ) }
function pdfcat() { ( for f in $@ ; do pdftotext "$f" - ; done ) }

# a script plotting the cumulative distribution function for a filesystem hierarchy
alias fstats='fstats.pl > /tmp/fstats.octave ; octave /tmp/fstats.octave  > /tmp/fstats.png ; fbi /tmp/fstats.png -a'

# a quick way to install a quick kernel (must be root)
alias kernelinstall='cp /boot/bzImage.gentoo /boot/bzImage.gentoo.bak && cp /usr/src/linux/arch/i386/boot/bzImage /boot/bzImage.gentoo'
alias kxmms='kill `pidof xmms` ; xmms&'
alias wget='wget -U Mozilla'

alias shredz='shred -z -n 1'
alias rmz='shredz'
alias vd='echo -e vd\\rq\\r | nc bibo 4000 | grep "\(\[D\)\|\(Up\)"'    #one shell escape is necessary, since the command will be bash-interpreted
alias m='mfind.sh'
alias mlkill='echo -e kill\\r | nc bibo 4000'
alias mkill=mlkill
alias v='vf;vd'
alias vs='vd|grep ^Down'
alias mt='mp3tool.pl'

# cdrom mounting / umounting aliases
alias cdrom='mount /mnt/cdrom ; ls -l /mnt/cdrom'
alias cdrom1='mount /mnt/cdrom1 ; ls -l /mnt/cdrom1'
alias dvd='cdrom1'
alias ucdrom='umount /mnt/cdrom && ej'
alias  cdromcheck='mount /mnt/cdrom ; cd /mnt/cdrom ; for i in *md5 ; do md5sum --check "$i" ; done'
alias cdrom1check='mount /mnt/cdrom1; cd /mnt/cdrom1; for i in *md5 ; do md5sum --check "$i" ; done'

alias mplayer='mplayer -vo x11 -vf scale=1024:768'

function foreachday()
{
        # for each day in the interval will eval supplied $@
        local Ym=2001
        local YM=2004
        local Mm=1
        local MM=10
        local Dm=1
        local DM=10
        for((y=$Ym;y<$YM;++y)); do for((m=$Mm;m<$MM;++m));do for((d=$Dm;d<$DM;++d)) ; do local DAY=$y"0"$m"0"$d ; eval `echo "$@" | sed s/DAY/$DAY/g`  ;done ;done;done 
        local Mm=10
        local MM=13
        local Dm=10
        local DM=32
        for((y=$Ym;y<$YM;++y)); do for((m=$Mm;m<$MM;++m));do for((d=$Dm;d<$DM;++d)) ; do local DAY=$y$m$d ; eval `echo "$@" | sed s/DAY/$DAY/g` ;done ;done;done 
        local Mm=1
        local MM=10
        local Dm=10
        local DM=32
        for((y=$Ym;y<$YM;++y)); do for((m=$Mm;m<$MM;++m));do for((d=$Dm;d<$DM;++d)) ; do local DAY=$y"0"$m$d ;eval `echo "$@" | sed s/DAY/$DAY/g` ;done ;done;done 
        local Mm=10
        local MM=13
        local Dm=1
        local DM=10
        for((y=$Ym;y<$YM;++y)); do for((m=$Mm;m<$MM;++m));do for((d=$Dm;d<$DM;++d)) ; do local DAY=$y$m"0"$d ;eval `echo "$@" | sed s/DAY/$DAY/g` ;done ;done;done 
}

# who am I connected to ?
alias peers="netstat --ip --inet --numeric-hosts | grep tcp  | sed -e 's/^\([a-z0-9:\.]\+ *\)\{4\}//g' | cut -f 1 -d ' ' |sed s/:.*$//g|sort|uniq"
#alias sscan='find / -fstype ! proc -perm -2 ! type l -ls 2>&1'
#xxd
# to uppercase and to lowercase
alias touc='perl -e  "while(<>){print(uc($_));};"'
alias tolc='perl -e  "while(<>){print(lc($_));};"'

# the jpeg file format comment manipulating command names are horrible
alias jpgcomread='rdjpgcom'
alias jpgcomwrite='wrjpgcom'

# re-sources aliases
alias aliasrefresh='. ~/.alias'

# vim uber alles
alias ivm='vim' # typos :)
alias vmi='vim' #typos :)
alias miv='vim' #typos :)
alias cim='vim' #typos :)
alias hea=head  # typos :)
alias grpe=grep # typos :)
alias greo=grep # typos :)
alias gerp=grep # typos :)

# blinking screen variable
export BLINK="\E[5m"

#function google() { local SE='http://www.google.com/search?q=';local BROWSER='links';local ARGS=`echo $@ |sed s/' '/+/g;`;$BROWSER $SE$ARGS;}
function credo() { local SE='http://credo.fub.it/cgi-bin/credo/search?query=';local BROWSER='firefox';local ARGS=`echo $@ |sed s/' '/+/g;`'&lang=en&d=t';$BROWSER $SE$ARGS;}
function mininova() { local SE='http://www.mininova.org/search/?search=';local BROWSER='links';local ARGS=`echo $@ |sed s/' '/+/g;`;$BROWSER $SE$ARGS;}
alias search='google'
alias rtf='unrtf'
alias doc='catdoc'



#http://www.jjj.de/shell/.alias:
alias m='make'
function lsd  { ( if test -d "$1";  then cd $1;  fi  &&  ls -ldF $(find . -maxdepth 1 -type d); ); }
function vv  { ## launch xdvi or gv according to type
    test -z "$1" && return;
    test -d $1 && { ls -lF $1; return; } 
    local F="${1##*/}"; # basename
    local S="${F%\.gz}"; # remove trailing .gz
    local S="${S%\.bz2}"; # remove trailing .bz2
    if test -z "${S:#*ps}"; then gv $1 &  return; fi
    if test -z "${S:#*pdf}" ; then gv $1 &  return; fi
    if test -z "${S:#*dvi}" ; then  xdvi $1 &  return;  fi
    less $1;
#echo "vv(): file $1 is of unknown type." 1>&2;
}
#function  ic  { echo -en "\033[2t"; }



alias u='cd ..'
alias uu='cd ../..'
alias uuu='cd ../../..'


alias merge='( cp.merge.sh ph/philezraw#0*/eb*/* ebooks )'

alias ascii='man ascii'

# having fun with fonts
alias setfont.flip='setfont -v ~/tmp/misc/LatArCyrHeb-16.psfu.flipped.gz'
alias flipfont='setfont.flip'
alias fontflip='setfont.flip'
alias fontflip.back='setfont'
alias flipfont.back='setfont'

alias date.s='date +%s'

# let's say you want an html document looking as a document viewed in vim
function vimsyntax()
{
        # should save in syntax-highlighted html files all of the proposed files..
        for f in $@
        do
                [ -f $f ] && vim -f -u /dev/null +"syn on!" +"so \$VIMRUNTIME/syntax/2html.vim" +"%s/<body bgcolor=\"#ffffff\" text=\"#000000\">/<body bgcolor=\"#000000\" text=\"#ffffff\">/g" +"wq!" +"q!" $f
        # note : on some vim versions, putting a ! after the substitution 'g' char causes error
        done
}

#alias fbi='/usr/bin/fbi'
alias matrixview='matview'
alias matrix='cmatrix'
function matrixmarkettom() { echo '#!/usr/bin/octave' ; echo -e 'm=[' ; cat "$1"  | grep -v '^%' |  sed 's/\b /,/g;s/$/;/g' ; echo '];s=sparse(m(2:size(m,1),1),m(2:size(m,1),2),m(2:size(m,1),3),m(1,1),m(1,2));'"v=s'*linspace(1,1,m(1,1))',sum(v)" ;  }
#http://math.nist.gov/MatrixMarket/mmio/matlab/mmiomatlab.html


alias a2ps.R="a2ps -R"

# audio recording
alias record='arecord'

[[ -f "/home/dez/uni/tesi/enea/bin/utils.sh" ]] && ( . "/home/dez/uni/tesi/enea/bin/utils.sh" ) # utilities for matrix market manipulation
function zhead(){ zcat $@ | head ; } 
alias sourcenavigator='snavigator'
#alias lightsoffon='( radeontool light off ; read ;radeontool light on ; )' # use exit hooks for security..


#alias fim='~/fim/fim'
alias fb='~/fim/src/fbgs.sh'
#alias fb=fimgs

function die() { echo $@ 1>&2 ; exit ; }

# information hunger
alias meteo='links www.meteorete.net/chetempofa.php'
alias meteo="lynx  -dump www.meteorete.net/chetempofa.php | grep -C 20 'previsione oggi'"

alias perlshell='perl -MCPAN -e shell'
alias ubuntuhelp='echo see sysv-rc-conf..'
alias headless="perl -e 'use Getopt::Std;getopts(\"n:\");if(\$opt_n==0){\$opt_n=1;}<> while \$opt_n--;print while(<>);'"        # does not work!
alias mpcnc=ncmpc # mpc client
alias aafire='nice -20 aafire'
alias cacafire='nice -20 cacafire'
alias fetchmailrc='$EDITOR ~/.fetchmailrc'
alias netstat.tuna='netstat -tuna'
alias cmatrix='nice -20 cmatrix'
alias functions='declare -f'
alias exif_remove_tag='exiftool -all= ' # this clears the EXIF tag from a file (note: doesn't remove, just clears)
alias nc=nc\ -vv
alias pl=pl\ -q
alias howto='cd /usr/share/doc/HOWTO/html/ && ll'
function puliziapdf() { grep -v  '^/Author\|^/CreationDate' $1 --text > /tmp/pdfpulito.pdf && mv /tmp/pdfpulito.pdf $1 ; }
alias translate="babelfish.pl"
alias babel="babelfish.pl"
alias utf.test="wget http://melkor.dnp.fmph.uniba.sk/~garabik/debian-utf8/HOWTO/download/UTF-8-demo.txt.gz -O - | zcat"

alias ctags.deep="ctags *{.c,.cpp,.h,.f90,.F90} */*{.c,.cpp,.h,.f90,.F90} */*//*{.c,.cpp,.h,.f90,.F90} *//*/*/*{.c,.cpp,.h,.f90,.F90} */*/*/*/*{.c,.cpp,.h,.f90,.F90} */*/*/*/*/*{.c,.cpp,.h,.f90,.F90} */*/*/*/*/*/*{.c,.cpp,.h,.f90,.F90} */*/*/*/*/*/*/*{.c,.cpp,.h,.f90,.F90} */*/*/*/*/*/*/*/*"
alias etags.deep="etags *{.c,.cpp,.h,.f90,.F90} */*{.c,.cpp,.h,.f90,.F90} */*//*{.c,.cpp,.h,.f90,.F90} *//*/*/*{.c,.cpp,.h,.f90,.F90} */*/*/*/*{.c,.cpp,.h,.f90,.F90} */*/*/*/*/*{.c,.cpp,.h,.f90,.F90} */*/*/*/*/*/*{.c,.cpp,.h,.f90,.F90} */*/*/*/*/*/*/*{.c,.cpp,.h,.f90,.F90} */*/*/*/*/*/*/*/*"
alias am=alsamixer
alias procmailrc='$EDITOR ~/.procmail/rc.lists'

function m3ufind() { echo '#EXTM3U' ; find "$@" -name '*mp3' ;  }
alias findm3u=m3ufind
alias eterm=Eterm
alias mpcnc=ncmpc
alias mp=mpcnc
alias m=mp
alias af=aliasfile

alias smart-questions='$BROWSER http://www.catb.org/~esr/faqs/smart-questions.html'
function m3ufind() { echo '#EXTM3U' ; find "$@" -name '*mp3' ;  }
alias coredump.on='ulimit  -S -c unlimited'



#alias mplayer='mplayer -vo x11 -vf scale=640:480'
alias grep='grep --color'
#echo  160.80.2.5 | sed 's/\([0-9]\+\)\.\([0-9]\+\)\.\([0-9]\+\)\.\([0-9]\+\)/\1*2**24+\2*2**16+\3*2**8+\4/' | perl -e 'print  eval <STDIN>'

# mencoder ../Power\ and\ Terror.mdf -ovc lavc -lavcopts vcodec=mpeg4:vpass=1 -oac mp3lame -lameopts vbr=3 -o /dev/null
# mencoder ../Power\ and\ Terror.mdf -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell:vpass=2 -oac mp3lame -lameopts vbr=3 -o output.avi
alias azureus='nice azureus'
function matrixmarkettom() { echo '#!/usr/bin/octave' ; echo -e 'm=[' ; cat "$1"  | grep -v '^%' |  sed 's/\b /,/g;s/$/;/g' ; echo '];s=sparse(m(2:size(m,1),1),m(2:size(m,1),2),m(2:size(m,1),3),m(1,1),m(1,2));'"v=s'*linspace(1,1,m(1,1))',sum(v)" ;  } 

alias vmi='vim'
#function mencoder.avi.1() { mencoder $1 -ovc lavc -lavcopts vcodec=mpeg4:vpass=1 -ni -oac mp3lame -lameopts vbr=3 -o /dev/null  ; }
#function mencoder.avi.2() { mencoder $1 -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell:vpass=2 -oac mp3lame -lameopts vbr=3 -o output.avi ; }

function pdfcropfirstpage()
{
        in="$1"
        out="$2"
        [ "$out" == "" ] && out="${in//.pdf/.NOFIRSTPAGE.pdf}"
        HELP="usage : $0 <infile.pdf> [<outfile.pdf>]\nIf no output file is specified, \".NOFRONTPAGE\" is appended to file name\nWarning: the input file should end with .pdf suffix (not .PDF, for example), or nasty things will happen!\n";
        [ "$1" == "" ] &&   echo -e "$HELP" && return
        [ "$1" == "-h" ] && echo -e "$HELP" && return
        [ ! -f "$in"  ] &&  echo -e "Error : there is no such pdf file : $in\n" &&  return -1
        [   -f "$out" ] &&  echo -e "Error : there is already a file named : $out\n" &&  return -1
        pdftk "$in" cat 2-end output "$out"
}
alias littotgz='for i in *.lit ; do d=${i/.lit/};[ -d "$d" ] && continue ; mkdir "$d" && clit "$i" "$d" && tar czf "$d".tgz "$d" && rm -fRd "$d" ; done'
alias littotgz_deep='for i in *.lit */*.lit */*/*.lit */*/*/*.lit */*/*/*/*.lit ; do d=${i/.lit/};[ -d "$d" ] && continue ; mkdir "$d" && clit "$i" "$d" && tar czf "$d".tgz "$d" && rm -fRd "$d" ; done'


function sed_rec()
{
        local where="$1"
        local from="$2"
        local to="$3"
        [ "$#" -lt 3 ] && return
        
        echo find "$where" -type f -exec sed "s/$from/$to/g" '{}' -i ';'
        find "$where" -type f -exec sed "s/$from/$to/g;" -i  '{}' ';' -exec ls -l '{}' ';'
}
alias unzip.stdin='funzip'
alias dups='fdupes'

alias daa='echo use poweriso!'

# information hunger
function wiki() { local SE='http://en.wikipedia.org/wiki/';local BROWSER='links';local ARGS=`echo $@ |sed s/' '/_/g;`;$BROWSER $SE$ARGS;}
function wikit() { local SE='http://it.wikipedia.org/wiki/';local BROWSER='links';local ARGS=`echo $@ |sed s/' '/_/g;`;$BROWSER $SE$ARGS;}
alias utf.test="wget http://melkor.dnp.fmph.uniba.sk/~garabik/debian-utf8/HOWTO/download/UTF-8-demo.txt.gz -O - | zcat"
BROWSER=elinks

#-------- BEGIN CHIP ONLY, NEW
function bookgrep() { grep -i "$@" ~/doc/pvt.chip/boo* ~/doc/notes/boo*  ; }
alias grepbook=bookgrep
#-------- END   CHIP ONLY, NEW
alias java-stuff=java-check-environment  # gentoo stuff :)
alias ruby-debug='ruby -rdebug'


alias agenda="wyrd"
alias scp='scp -p'
alias killa='killall -9'

alias dvd.rip='acidrip'
alias rip.dvd='acidrip'
#alias scm='guile'
alias highlight-sources="sources-highlight"



function acrowget() { wget $1 -O $TMPDIR/acrotemp.pdf && acroread $TMPDIR/acrotemp.pdf && rm -f  $TMPDIR/acrotemp.pdf  ; }
fileheader() { TAG="$1" ; shift ; until test "$1" = "" ; do [ -f "$1" ] && ( read LUKS < $1 ; [[ "${LUKS}" =~ "$TAG" ]] && echo "$1 : $LUKS"; ) ; shift ; done ;  }
function isluks() { fileheader "LUKS" $@ ;  }

alias asciieditor=aewan
alias b=$BROWSER
alias moutn=mount

alias quake3.softwaregl='quake3-bin "+set r_allowSoftwareGL 1"'
alias tfim='fim -t'
alias tim='tfim'


ssh_authorized_keys_colonize()
{
        [ "$1" == "" ] && echo "[!] usage : ssh_authorize_keys_colonize user@host " && return
        PKF="$HOME/.ssh/id_rsa.pub"
        [ ! -f "$PKF" ] && ( echo "[!] no $PKF!" && return )
        PK=$( cat $PKF | sed s/$USER@$HOSTNAME//g )
        [ x"$PK" == x"" ] && ( echo "[!] problems reading $PKF!" && return )
        AKF=".ssh/authorized_keys"
        # the following will not probably work on some shells
        ssh $1 "mkdir -p .ssh;chmod 0700 .ssh;touch $AKF;chmod 644 $AKF;   grep \"$PL\" $AKF || echo $PK >> $AKF;"
}


alias bibo_ip='ssh bauman.ce.uniroma2.it cat ipa || ssh martone@claudius.ce.uniroma2.it cat ipa'
alias ssh_bibo='ssh `bibo_ip | sedips_nl | grepips`'
function append() { sed "s/\$/$@/g"; }

alias killttys='kill -9 ` ps ax | grep tty | grep bash | cut -d " " -f 2  `'

alias charset_rename=convmv

function sse_inquiry()
{
        case "$1" in 
        -h|'') echo "this function looks if the supplied program was compiled for SSE2 and on  ";;
        *)     objdump -d -- "$1"  | grep -i '%xmm' ;;
        esac
}

function nm_ldd_grep()
{
 lib=$1
 sym=$2
 ( for l in `ldd $lib | grep '=>' | sed 's/^.*=>.//g' | sed 's/\s(.*).*$//'|sed 's/ /_/g' | sort | uniq ` ; do nm $l ; done ) | grep -i '^.*'"$sym"  2>/dev/null
}

alias debiankernelpurge="dpkg --purge --force-remove-essential linux-image-2.6.25-2-686"

#alias cmount='sudo /sbin/losetup /dev/loop0 /home/dez/documents.crypted && sudo /sbin/cryptsetup luksOpen /dev/loop0 dezdocs && sudo /bin/mount -t ext3 /dev/mapper/dezdocs /home/dez/dezdocs'
#alias cumount='sudo /bin/umount /dev/mapper/dezdocs && sudo /sbin/cryptsetup luksClose dezdocs && sudo /sbin/losetup -d /dev/loop0'

alias gpg='gpg --no-emit-version'
alias wgetnull='wget -O /dev/null'

#alias ip='ping -R -c 1 sf.net | grep 84.22'
alias ip='ping -R -c 1 sf.net'
alias last.foreigners='(last | grep -v "$USER\|root\|reboot")'

alias tsc="sed 's/\([ \t]*[0-9a-f]*:[ \t]*\)\(\(\([a-f]\|[0-9]\)\{2\}[ \t]\)*\)\(.*\)/\2/g;s/\(\([a-f]\|[0-9]\)\{2\}\)/\\\\x\1/g;s/[ \t]//g;''s/^/\"/g;s/$/\"/g'"

function etimo() { links "www.etimo.it/?term=""$@" ; } 
function wikipedia() { links "en.wikipedia.org/wiki/""$@" ; } 
function demauro(){ local s=$1 ; shift ; wget -O - http://www.demauroparavia.it/cerca  --post-data="stringa=$s" > /tmp/demauro.tmp.html && links  /tmp/demauro.tmp.html && rm /tmp/demauro.tmp.html ; }

# multimedia file conversion aliases
alias mpeg4='echo m4a files are managed with faa{cd} :\)'
alias m4atomp3='(for f in *.m4a ; do mplayer -vo null -vc dummy -af resample=44100 -ao pcm -ao pcm:waveheader "$f" && lame -m j -h -b 192  audiodump.wav -o "${f//.m4a/.mp3}"; done ; rm audiodump.wav )'
alias m4atomp3_low='(for f in *.m4a ; do mplayer -vo null -vc dummy  -ao pcm -ao pcm:waveheader "$f" && lame -m j -b 64  audiodump.wav -o "${f//.m4a/.mp3}"; done ; rm audiodump.wav )'
alias oggtomp3='( for f in *.ogg ; do oggdec -o   "$f".wav "$f" ; lame -h -b 192 "$f".wav "${f//.ogg/.mp3}" ; rm "$f".wav ; done )'
alias mpctomp3='( for f in *.mpc ; do mppdec "$f" "$f".wav      ; lame -h -b 192 "$f".wav "${f//.mpc/.mp3}" ; echo rm "$f".wav ; done )'
alias flactomp3='( for f in *.flac ; do flac -d "$f"  ; lame -h -b 192 "${f//.flac/.wav}" "${f//.flac/.mp3}" ; rm "${f//.flac/.wav}" ; done )'
alias wavtomp3='( for f in *.wav ; do lame -h -b 192 "$f" "${f//.wav/.mp3}" ; done )'
alias aifftomp3='( for f in *.aiff ; do lame -h -b 192 "$f" "${f//.aiff/.mp3}" ; done )'
alias shntomp3='( for f in *.shn ; do shorten -x "$f" "${f//.shn/.wav}" ; lame -h -b 192 "${f//.shn/.wav}" "${f//.shn/.mp3}" ; rm "${f//.shn/.wav}" ; done )'
alias apetomp3='( for f in *.ape ; do  ape "$f" "${f//.ape/.wav}" -d &&  lame --quiet -h -b 192 "${f//.ape/.wav}" "${f//.ape/.mp3}" &&  echo rm "${f//.ape/.wav}" ; done )'
alias mpptomp3='mpctomp3'

# date resync : note that a non null MOTD would break this
function date_sshfetch() { echo 'this is insecure : are you sure ?' && read &&  [ -z "$@" ] || date --date "`ssh $1`" ; }