Source

dotfiles / shell / functions

## Functions
add_auth_key () {
    host=$1
    
    if  [ -z $host ] ; then
        echo "You must provide a host as the first (and only) argument"
        return
    fi
    
    if [ -f `which ssh-copy-id` ]; then
        command `which ssh-copy-id` $host
    else
        if [ ! -f ~/.ssh/id_rsa.pub ] ; then
            command ssh-keygen -t rsa
        fi
        command scp ~/.ssh/id_rsa.pub $host:/tmp/tmp_rsa
        command ssh $host -t "if [ ! -d ~/.ssh ]; then mkdir ~/.ssh/;fi && cat /tmp/tmp_rsa >> ~/.ssh/authorized_keys && rm /tmp/tmp_rsa && chmod -R 700 ~/.ssh"
    fi
}

svim (){
    # Run vim as super user
    command sudo vim $@
}

extract () {
    if [ -f $1 ] ; then
        case $1 in
            *.tar.bz2)  tar xjf $1      ;;
            *.tar.gz)   tar xzf $1      ;;
            *.bz2)      bunzip2 $1      ;;
            *.rar)      unrar x $1      ;;
            *.gz)       gunzip $1       ;;
            *.tar)      tar xf $1       ;;
            *.tbz2)     tar xjf $1      ;;
            *.tgz)      tar xzf $1      ;;
            *.zip)      unzip $1        ;;
            *.Z)        uncompress $1   ;;
            *)          echo "'$1' cannot be extracted via extract()" ;;
        esac
    else
        echo "'$1' is not a valid file"
    fi
}

dict () {
    grep "$@" /usr/share/dict/words
}

exip () {
    # gather external ip address
    echo -n "Current External IP: "
    curl -s http://checkip.dyndns.com/ | grep "<body>" | sed -e 's/<html><head><title>Current IP Check<\/title><\/head><body>Current IP Address: //g' -e 's/<\/body><\/html>//g'
}

ips () {
    # determine local IP address
    /sbin/ifconfig | grep "inet " | awk '{ print $2 }'
}

shell () {
    ps | grep `echo $$` | awk '{ print $4 }'
}

export TD="$HOME/Dropbox/Temp/`date +'%Y-%m-%d'`"

td () {
	mkdir -p $TD
	cd $TD
}

wikipedia () {
    dig +short txt ${1}.wp.dg.cx
}

port_scan () {
    nmap -A -T4 ${1}
}

encrypt () {
  `which openssl` bf -a -in "${1}"
}

decrypt () {
  `which openssl` bf -d -a -in "${1}"
}