Craig's Linux Notes: My .bashrc file

Last modified: 01/01/2007
# ~craig/.bashrc

#############
## Bash stuff
#############

# This configuration file is loaded everytime a new shell is started, causing
# definitions of the form X=$X:... to grow with each invocation.
# To limit their growth, the initial value of $X, if any, is stored in a
# variable called X_BASE that is never altered once set, and the assignment of X
# is performed only when this configuration file is read for the first time, or
# when it is altered.

# The following non-exported variable is set to non-zero when this .bashrc
# configuration file has changed.
_NEW_BASHRC_TIMESTAMP=`date --reference=$HOME/.bashrc`
if [ "$_BASHRC_TIMESTAMP" != "$_NEW_BASHRC_TIMESTAMP" ]; then
    # The following variable contains the timestamp of the .bashrc file
    # used to assign the environment variables.
    export _BASHRC_TIMESTAMP=$_NEW_BASHRC_TIMESTAMP

    # The following non-exported variable is set to indicate that the .bashrc
    # file has changed, or is being read for the first time.
    _BASHRC_CHANGED=1
else
    # The following non-exported variable is set to indicate that the .bashrc
    # file has not changed.
    _BASHRC_CHANGED=0
fi


# _assign_base  X
# The following function assigns X_BASE to the value of X if either X_BASE is
# currently undefined or this .bashrc has changed. Returns true (0) if the
# assignment is made, and false (1) otherwise.
_assign_base() {
    if [ -z "${1}_BASE" -o $_BASHRC_CHANGED -eq 1 ]; then
	eval "export ${1}_BASE=\$$1"
	return 0
    else
	return 1
    fi
}




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

# Set up a colored prompt.
if [ "$TERM" = "xterm" ]; then
    # Note the \[ and \], which tell Bash to ignore the material inside
    # (control sequences) when calculating the prompt length. These are
    # required for command line editing to work smoothly.
    PS1="\[\]${PS1}\[\]"
fi


# Add more stuff to the command search path
if _assign_base PATH; then
    PATH=$PATH_BASE:/sbin:/usr/sbin:$HOME/bin
fi




######
## CVS
######

export CVSROOT=:local:/home/cvsroot
export CVSUMASK=007
export EDITOR=emacs




#####
## ls
#####

# colors that "ls" uses.
# Run 'dircolors --print-database' to see a description, and
# run 'dircolors --csh' to print out the format (approximately).
export LS_COLORS='no=00:fi=00:di=01;34:ln=01;43;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=01;32;41:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=01;31:*.rpm=01;31:*.jpg=01;35:*.png=01;35:*.gif=01;35:*.bmp=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.png=01;35:*.mpg=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:'

export LS_OPTIONS='--color=tty -F'

alias l.='ls -d .[a-zA-Z]* $LS_OPTIONS'
alias ll='ls -l $LS_OPTIONS'
alias ls='ls $LS_OPTIONS'

# Makes 'ls' and 'du' to report in scientific units.
export BLOCK_SIZE=si




#####
## ps
#####

alias psa='ps -Ao pid,args --forest'




##############
## Development
##############

# Development projects are subdirectories in the directory ~/projects.
# Each subdirectory is named for the project.

# The following variables are common to all projects.
if [ $_BASHRC_CHANGED -eq 1 ]; then
    export JAVA_HOME=/usr/java/jdk1.3.1_01
    export JRE_HOME=/usr/java/jre1.3.1_01
    export TOMCAT_HOME=/usr/java/jakarta-tomcat-3.2.1
    export CLASSPATH_BASE=.:/usr/java/jakarta-servletapi-3.2/lib/servlet.jar
    export LD_LIBRARY_PATH_BASE=$LD_LIBRARY_PATH
    export DEV_PATH_BASE=$JAVA_HOME/bin:$TOMCAT_HOME/bin:$PATH
fi

# Sets the current project configuration. Usage:
#  set_project  
# Where:
#   project-dir   Name of subdirectory in the ~/projects directory.
# Sets and exports the variables:
#   PROJECT   Name of current project.
# Before setting the new project, evaluates the file $PROJECT/.project of
# the current project with the variable LEAVING_PROJECT=1 to undo environment
# variable settings.
# Then evaluates the file $PROJECT/.project of the new project for additional
# environment variable settings. Generally, all of the variables should be exported.
set_project() {
    if [ -n "$PROJECT" -a -e "$PROJECT/.project" ]; then
	LEAVING_PROJECT=1
	source "$PROJECT/.project"
	unset LEAVING_PROJECT
    fi

    export PROJECT=~/projects/$1
    if [ -n "$PROJECT" -a -e "$PROJECT/.project" ]; then
	source "$PROJECT/.project"
    fi
}


# "topdir" command sets directory to top of project. Return to previous
# directory with "popd". Relies on the environment variable PROJECT.
topdir() {
    pushd $PROJECT
}

Copyright © 2002 Craig Lawson
Index no-thank-you-spam-i-am@i-hate-spam.spam.spam Document made with Nvu