My Dot Bashrc File

#!/bin/bash
# Author: Terence Tong

# set my prompt to be username@host:dir >
export PS1='\u@\h:\w> '

#####################################################################
# my safe rm

export _DELETE_DIR="$HOME/deleted"
export _TEMP_DIR="$HOME/temp"

alias remove="`which rm` -rf"
alias origrm="`which rm`"
alias origmv="`which mv`"

# override rm with my safe mv
function rm () {
  for item in $*; do
    origmv -f $item $_DELETE_DIR 2> /dev/null > /dev/null
  done
}

alias emptybin="cd $HOME; remove $_DELETE_DIR ; mkdir $_DELETE_DIR"

function clean () {
    rm core *~ \#* *\# .*~ .~* .*\# .\#* 2> /dev/null
}

[ -d $_DELETE_DIR ] || mkdir $_DELETE_DIR
[ -d $_TEMP_DIR ] || mkdir $_TEMP_DIR

#####################################################################
# setting a right display variable
[ ! -n "$SSH_CLIENT" ] || export DISPLAY=`echo $SSH_CLIENT | awk '{print $1}'`:0

# tired of cd ing, expecially in that damn tinyos project!
alias up1='cd ..'
alias up2='cd ../..'
alias up3='cd ../../..'
alias up4='cd ../../../..'
alias up5='cd ../../../../..'

# useful when something is added/modified/deleted
alias bashup='. ~/.bashrc'

# set default editor
export EDITOR="emacs"
export VISUAL="emacs"

# set autologout, to 15 minutes
# export TMOUT="900"

# try "ansi" for TERM?
export TERM="rxvt"

# just interesting in my queue
alias lpq="lpq | grep ' `whoami`'"

# split 1 page to 6 page
alias ps2ps6="psnup -6 -1 $1.ps $1-6.ps"

# the mighty path
export PATH=$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

# copy from somewhere, don't know how it works
# remove duplicate path
export PATH=$(echo $PATH | awk -F: '
{ for (i = 1; i <= NF; i++) arr[$i]; }
END { for (i in arr) printf "%s:" , i; printf "\n"; } ')

# don't like people to read/write/execute my file by default
# default permission is 700
umask 077

# my style to format c code
alias mystyle="astyle.exe -C -S -K -a -O -p -o -s2"

# remove all lines from a file
alias removeemptylines="sed -i -e '/^$/d'"
# spend too much time on this, I can't get it simpler. ai well, but it works
# undo emacs "fill paragraph"
function unwrap() {
  sed 's/ *$/ /g' $1 > $1.tmp;
  sed ':a; /[a-zA-Z0-9] $/N; s/\([a-zA-Z0-9]\) \n/\1 /; ta' $1.tmp > $1-unwrap
  rm $1.tmp
  echo "Look at $1-unwrap for your unwrapped output"
}

# my colorful aterm
# this color shows up nice in black background
ATERM_COLOR=( white yellow green cyan )

function aterm() {
  `which aterm` -fg ${ATERM_COLOR[`expr $RANDOM % ${#ATERM_COLOR[*]}`]}
}

# not everyone can use /usr/sbin/killall 
function killbyname() {
  TMP=`ps -U $LOGNAME | grep "$1" | awk {'print $1'}`
  [ -z "$TMP" ] || kill -9 $TMP
}


#####################################################################
# cvs stuff
export CVS_RSH="ssh"
export CVSEDITOR="nano" # nano is more popular than pico

# this is for local cvs
# export CVSROOT="/home/t/tm/tmtong/.cvs"

alias ocfcvs="export CVSROOT=:ext:tmtong@ocf.berkeley.edu:/home/t/tm/tmtong/.cvs"

#####################################################################
# postgresql stuff
alias startserver="pg_ctl start -o '-i'"
alias stopserver="pg_ctl stop"

#####################################################################
# load ssh key to memory
alias sshstart='eval `ssh-agent`; ssh-add'

# login shortcut
alias ocf='ssh tmtong@ocf.berkeley.edu'





Written by Terence Tong
Statistics:
Go back to Home