Saturday, March 10, 2012

My perfect (for what i need now) ~/.bashrc


#Make the terminal prompt my own :P
PS1='@\W~>'
shopt -o -s vi


#Some shortucts 
#for cv programming esp.
alias gcv='gcc -ggdb `pkg-config --cflags opencv`  `pkg-config --libs opencv`'
alias rmmake='rm CMakeCache.txt CMakeFiles/ cmake_install.cmake Makefile -rf'


#very useful to do autoshutdown. well, saves me some typing, that's all.
alias closeafter='sudo shutdown -hP'


#to open the last edited progrram in either gvim or vi
#useful when i'm solving c puzzles.
function vic {
HEADFILE=`ls -t1 | grep [.]c| head -n 1` 
vi  $HEADFILE
}
function gvic {
HEADFILE=`ls -t1 | grep [.]c |head -n 1` 
gvim  $HEADFILE
}
function gccc {
HEADFILE=`ls -t1 | grep [.]c |head -n 1` 
gcc -Wall -g $HEADFILE -o `basename $HEADFILE .c`
}
function runc {
HEADFILE=`ls -t1 | grep [.]c |head -n 1` 
./`basename $HEADFILE .c`
}
function gdbc {
HEADFILE=`ls -t1 | grep [.]c |head -n 1` 
gdb `basename $HEADFILE .c`
}
##very very useful.
alias ggl='g++ -lglut -lGL -lGLU -lGLEW '


#pure lol function. my terminal window vibrates when there is an alarm or error. so i 
#just produce alarm in infinite loop :D
alias vibrator='while who &>/dev/null ; do printf "\a" ; done'


##complex piece of shit - but works perfectly for me now. Love this. Used to initialize byobu
# properly so it doesnt open a new byobu if byobu is open in a terminal, and connects to the 
#old byobu if byobu is already running.
if [ `ps aux |grep -v 'grep '| grep SCREEN | wc -l ` -gt 0 ]
then
 if [ `ps aux |grep -v 'grep '| grep 'screen -c' | wc -l ` -gt 0 ]
 then
  who >& /dev/null
 else
  byobu
 fi
else
 byobu
fi


##i always forget this alias even exists.
alias editbashrc='vi ~/.bashrc'
##even this :D i forgot. will use this .
alias updatebashrc='source ~/.bashrc'



#script to turn off monitor or turn on monitor
function offmonitor {
 xset +dpms
 status=`xset -q | grep "Monitor is"`
 status=`echo $status | sed 's/.*[^\w] //'`
 if [ $status = "On" ]
 then
  echo turning off...
  xset dpms force off
 else
  echo already off...
 fi
}


##functions written to backup my data with date info. it's such a pain to look up the backup 
#method and back up data again and again. though the following is a primitive way of backing 
, i think it might just serve the purpose when disaster strikes. I hope restoring these 
#files will get my future comp back in running state.
function backup_madi {
 today=`date +%d%b`
 sudo tar cvpzf /disk/backup/backup_$today.tgz --exclude=/proc --exclude=/lost+found 
--exclude=/disk --exclude=/mnt --exclude=/sys --exclude=/home/siddhartha/.axel/* 
--exclude=/home/siddhartha/{Documents,Downloads,Music,Videos,Pictures} 
--exclude=/home/siddhartha/.Virtualbox/* /
     echo Backup done on $today. >> /disk/backup/log.log
}
function storemycodes {
 today=`date +%d%b`
 sudo tar cvpzf /disk/backup/codes_$today.tgz /home/siddhartha/Documents/programs/
 echo Code backup done on $today. >> /disk/backup/log.log
}


##four functions that act as a set of notemakers for me. These functions were written by me
# when i was jobless :D Anyway, what it does is pretty muchh obvious. they take notes from 
#me and store them in a new/existing file in a particular folder. i use the same scripts to 
#view those notes, list them or delete them too.
function note {
 notestack=$1
 current=`pwd`
 cd /home/siddhartha/Documents/notes/
 shift
 if [ $1 = '+' ]
 then
 append=1
 shift
 else
 append=0
 fi
 takenote=$*
 if [ $append -eq 0 ]
 then
 echo       '----------------'  >>$notestack
 echo `date '+%T, %a %d/%m/%y'` >> $notestack
 echo       '----------------'  >>$notestack
 fi
 echo $takenote >> $notestack
 echo note added to $notestack
 cd "$current"
}
function shownote {
 notestack=/home/siddhartha/Documents/notes/$1
 cat $notestack
}
function rmnote {
 notestack=/home/siddhartha/Documents/notes/$1
 rm  $notestack
}
function lsnote {
 notestack=/home/siddhartha/Documents/notes/
 ls $notestack
}

No comments:

Post a Comment