#######################################################
# slackmaGic's .bashrc file
# IRC ##slackware @ freenode
# www.slackmagic.com
#
# Last Modified 07-14-2013
#######################################################

# User specific aliases and functions

# Source global definitions
#if [ -f /etc/bashrc ]; then
#	. /etc/bashrc
#fi

# Define a few COLORS
liBlack="\[\033[0;30m\]"
boBlack="\[\033[1;30m\]"
liRed="\[\033[0;31m\]"
boRed="\[\033[1;31m\]"
liGreen="\[\033[0;32m\]"
boGreen="\[\033[1;32m\]"
liYellow="\[\033[0;33m\]"
boYellow="\[\033[1;33m\]"
liBlue="\[\033[0;34m\]"
boBlue="\[\033[1;34m\]"
liMagenta="\[\033[0;35m\]"
boMagenta="\[\033[1;35m\]"
liCyan="\[\033[0;36m\]"
boCyan="\[\033[1;36m\]"
liWhite="\[\033[0;37m\]"
boWhite="\[\033[1;37m\]"


# Enable 256 Colors for bash prompt
function EXT_COLOR () { echo -ne "\[\033[38;5;$1m\]"; }

PS1="\n $boBlack($liBlack`EXT_COLOR 32`\$(ls -lah | grep -m 1 total | sed 's/total //')B, \$(ls -1 | wc -l | sed 's: ::g') files$boBlack)`EXT_COLOR 234`\342\224\200\342\224\200\342\224\200\342\224\200\342\224\200\342\224\200\342\224\200\342\224\200\342\224\200\342\224\200[ $liBlack`EXT_COLOR 59`\T \d $boBlack`EXT_COLOR 234`]\342\224\200\342\224\200\342\224\200\342\224\200\342\224\200\342\224\200\342\224\200\342\224\200\342\224\200\342\224\200$boBlack[ `EXT_COLOR 220`\u$boBlack@`EXT_COLOR 156`\h$boBlack ] \n $boBlack(`EXT_COLOR 33`\w$boBlack) $boWhite>$liWhite "

PS2="> "
PS3="> "
PS4="+ "

# EXPORTS
#######################################################
shopt -s histappend	 		#append new history to existing file rather than rewriting - saves everything now!
shopt -s cdspell 			#ignore simple mistakes such as otp instead of opt or ect instead of etc
shopt -s cmdhist			#multiple line commands stay together in history
shopt -s extglob			#needed for working with files EXCEPT specific ones
PROMPT_COMMAND='history -a'
export HISTFILESIZE="12000" 		#the bash history should save 3000 commands
export HISTSIZE="12000"
export HISTCONTROL="ignoredups" 	#don't put duplicate lines in the history
export HISTIGNORE="&:ls:ll:lt:clear:q:[bf]g:exit"	#will ignore a few common commands
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/lib/pkgconfig/"
export PATH=$PATH:/usr/bin/ta-lib-config:/usr/lib/qt:/sbin:/opt/kde/bin/:/home/magician/scripts/:
export GREP_COLOR="1;32"
export QTDIR="/usr/lib/qt"

# Sets the Mail Environment Variable
MAIL=/var/spool/mail/magician && export MAIL

export EDITOR="vim"
export VISUAL="vim"
export n900='user@192.168.1.6:/home/user/MyDocs/'


#clock - A bash clock that can run in your terminal window.
function clock ()
{
	while true;do clear;echo "===========";date +"%r";echo "===========";sleep 1;done
} 

# A much better calendar
function today()
{
    local TMPDATE PARAM DASFILE
    TMPDATE=$(date '+%m %Y')
    PARAM=$(date '+%e ')
    DASFILE="$HOME/.idag_tmp.$$"

    cal -m $TMPDATE > $DASFILE

    cat $DASFILE | \
        sed -e "s/$PARAM/`tput smso`&`tput rmso`/"  
    
    echo -e "      \c"
    date '+%T'
    date '+%a %d/%m/%y Week %V'

    /bin/rm -f $DASFILE  # /bin/rm so that my rm alias wont get it...
}

# CALCULATOR
function calc
            {
             echo "${1}"|bc -l;
            }

# WEATHER - Usage: weather ZIPCODE or weathernow ZIPCODE for current conditions
weathernow() { lynx -dump "http://mobile.weather.gov/port_zh.php?inputstring=$*" | sed 's/^ *//;/ror has occ/q;2h;/__/!{x;s/\n.*//;x;H;d};x;s/\n/ -- /;q';}
weather(){ curl -s "http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query=${@:-<YOURZIPORLOCATION>}"|perl -ne '/<title>([^<]+)/&&printf "%s: ",$1;/<fcttext>([^<]+)/&&print $1,"\n"';}

# translate.google.com - USAGE: translate <phrase> <source-language> <output-language>
# Example: translate hello en es
translate(){ wget -qO- "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=$1&langpair=$2|${3:-en}" | sed 's/.*"translatedText":"\([^"]*\)".*}/\1\n/'; }


# Wikipedia via dig
function wiki ()
{
		  dig +short txt $1.wp.dg.cx; 
		 }


# Fetch my IP address
function myip()
{
lynx -dump -hiddenlinks=ignore -nolist http://checkip.dyndns.org:8245/ | awk '{ print $4 }' | sed '/^$/d; s/^[ ]*//g; s/[ ]*$//g'
}

function my_ps()
{
ps $@ -u $USER -o pid,%cpu,%mem,bsdtime,command ; 
}


function pp()
{
my_ps f | awk '!/awk/ && $0~var' var=${1:-".*"} ;
}


function ii()   # get current host related info
{
	  echo -e "\nYou are logged on ${RED}$HOST"
	    echo -e "\nAdditionnal information:$NC " ; uname -a
	      echo -e "\n${RED}Users logged on:$NC " ; w -h
	        echo -e "\n${RED}Current date :$NC " ; date
		  echo -e "\n${RED}Machine stats :$NC " ; uptime
		    echo -e "\n${RED}Memory stats :$NC " ; free
		      my_ip 2>&- ;
		        echo -e "\n${RED}Local IP Address :$NC" ; /sbin/ifconfig | awk /'inet addr/ {print $2}'
			   echo -e "\n${RED}ISP Address :$NC" ; myip
			    echo
		    }

treegraph() # Graphical tree of sub-directories
{
		  ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
}

cmdoften() # List of commands you use most often
{
		  history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head
}

# ls
alias ls='ls --color=auto'
alias lx='ls -lXB --color=auto'		# sort by extension
alias lk='ls -lSr --color=auto'              # sort by size
alias lc='ls -lcr --color=auto'		# sort by change time  
alias lu='ls -lur --color=auto'		# sort by access time   
alias lr='ls -lR --color=auto'               # recursive ls
alias lt='ls -lStr --color=auto'              # sort by date
alias lm='ls -al  --color=auto |more'         # pipe through 'more'
alias tree='tree -Csu'		# nice alternative to 'ls'
alias lsdir='ls -d */'		# list only directories
alias ll='ls -l --color=auto'
alias la='ls -al --color=auto'
alias lisa='ls -lisa --color=auto'
alias lsperm='ls -l | sed -e 's/rwx/7/g' | sed -e 's/r--/4/g' | sed -e 's/r-x/5/g' | sed -e 's/rw-/6/g' | sed -e 's/---/0/g''
alias lssize='du -s * | sort -n | more'
alias rm='rm -v'
alias mv='mv -v'
alias cp='cp -v'
alias grep='grep --color=auto'
alias mount='mount | column -t'

# ssh
#alias scp='scp -P 2222'
#alias ssh='ssh -p 2222'

# editing files
alias addalias='leafpad $HOME/.bashrc'
alias addflux='leafpad $HOME/.fluxbox/menu'

# general
alias ..='cd ..'
alias ...='cd ../..'
alias q='exit'
alias psaux='ps ax -eo user,pid,priority,args'
alias ping='ping -c 10'
alias openports='netstat -nape --inet'

alias nosound='for i in *; do mplayer "$i" -nosound; done'
alias fullscreen='for i in *; do mplayer "$i" -fs; done'
alias fullscreennosound='for i in *; do mplayer "$i" -fs -nosound; done'

alias 256colors='for code in {0..255}; do echo -e "\e[38;05;${code}m $code: Test"; done'
alias spacewaste="du -s * | sort -n | tail"
alias connectednow="lsof -P -i -n"
alias RTFM="echo -e '\033[1;33m'' http://xkcd.com/293/'"
alias sbcheck='lynx -dump http://slackbuilds.org/ports/12.1/ | grep slackbuilds.org | grep "tar.gz$" | cut -f6 -d/ | sed -e 's/.tar.gz//''
alias n900='ssh user@192.168.1.6'

alias OLDrecordmydesktopsection='recordmydesktop -x 240 -y 140 -width 800 -height 600 --v_quality 63 --v_bitrate 2000000 -o recordingdesktop.ogg'
alias OLDrecordmydesktop='ffmpeg -f x11grab -s 1920x1080 -r 30 -i :0.1 -sameq recordingdesktop.mpg'
alias recorddisplay0="ffmpeg -f alsa -ac 2 -i hw:0,0 -f x11grab -r 30 -s 2560x1600 -i :0.0 -acodec pcm_s16le -sameq desktop0recording.avi"
alias recorddisplay0_nosound="ffmpeg -f x11grab -r 30 -s 2560x1600 -i :0.0 -acodec pcm_s16le -sameq desktop0recording.avi"
alias recorddisplay1="ffmpeg -f alsa -ac 2 -i hw:0,0 -f x11grab -r 30 -s 1920x1080 -i :0.1 -acodec pcm_s16le -sameq desktop1recording.avi"
alias recorddisplay1_nosound="ffmpeg -f x11grab -r 30 -s 1920x1080 -i :0.1 -acodec pcm_s16le -sameq desktop1recording.avi"

