User:Bseklecki/.bashrc
Jump to navigation
Jump to search
# Brian A Seklecki's general bash_profile.
#
# $Id: .bash_profile,v 1.10 2002/12/24 01:50:21 lavalamp Exp lavalamp $
#
# ~/.bash_login not needed
# Maintained on mercury.hq.sgi.net (mercury.int.crane.stargate.net) from late 1998 -> late 2001
# Entered into CVS on addiction.spiritual-machines.org on Sun Mar 10 20:32:00 EST 2002
# At that time, decided to re-write quite a bit due to new reference:
# "Learning the BASH Shell" -- O`Reilly & Associates -- 2nd Edition
# Set the prompt - made for using a nice terminal like SecureCRT on a box that does at least 1280x1024
# export PS1='[\d @ \@] \u@\h:$PWD\$ '
# old school PS1 12/11/00
# Some 'To-Do's
#
####
# *) READ A BLOODY CONF FILE
# *) Use functions()
# *) better use of $UNAME cases
# *) Cleaner output @ login
# *) Need X/11 $DISPLAY hashing to test for SSH Tunnel Forwarding
#####
####
# All functions and prototypes below this point
####
# we need a quick check here because $OLDPWD doesn't get
# reset if you just press enter, and it SHOULDN'T
# so you can "cd -", but we need some way of telling
# we've been here before so the first IF doesn't false
# positive on us!
function getDirDiskUsage {
local CFN=".curDirDiskUsage"
# KEY NOITE: THE CACHE IS ONLY GOOD ONCE WE'RE IN THE DIR
# ONCE WE LEAVE THE DIR WE NEED TO REMOVE IT
if [ -r $CFN ] ; then
# we have a cachefile
# must have just pressed enter from last prompt
#echo -n "D1 "
echo -n $(cat $CFN)
elif [ -w . ] ; then
# IN A SUBDIR OF ~ AND -->
# NO CACHE-FILE, REMOVE LAST DIR'S STALE CACHE FILE
# AND DO THE THE CACHE FOR NEW DIR
#echo -n "D2 "
if [ -w $OLDPWD/$CFN ]; then
rm $OLDPWD/.curDirDiskUsage
fi
echo -n $(du -Hs . 2>/dev/null | awk '{print $1}') > $CFN
echo -n $(cat $CFN)
else
# MUST NOT BE IN ~ SUBDIR OR WRITEABLE DIR
# JUST DO DU(1)
#echo -n "D3 "
if [ -w $OLDPWD/$CFN ]; then
rm $OLDPWD/.curDirDiskUsage
fi
echo -n $(du -Hs . 2>/dev/null | awk '{print $1}')
fi
}
function getNumberOfJobs {
wcOut=$(jobs | wc -l | sed -e 's/space://g')
echo -n $wcOut
}
function parseDFAlias {
# the df alias is very special
# no two OSs share the same syntax, although they all claim to be posix compliant
# hmmm
# setup to print inodes as well
# use 'human readable' flag if possible
# ASSUME $BLOCKSIZE IS SET
case $_uname in
NetBSD*)
alias df="/bin/df -i"
;;
OpenBSD*)
alias df="/bin/df -i"
;;
FreeBSD*)
alias df="/bin/df -iH"
;;
Linux*)
alias df="/bin/df -h"
;;
SunOS*)
alias df='/usr/bin/df -F ufs -o i ; echo "*****************************************************************" ; /usr/bin/df -k'
;;
esac
#close function
}
function setUpX11 {
case $DISPLAY in
":0"*)
echo "# X/11 Style : Local"
echo "# X/11 Display : $DISPLAY"
;;
"")
echo "# X/11 Style : Disabled"
;;
*) if [ -n "$SSH_CLIENT" ]; then
echo "# X/11 Style : Unknown/Remote CLEARTEXT"
echo "# X/11 Display : $DISPLAY"
else
echo "# X/11 Style : Remote/SSH Tunnel"
sshDisplayIp=$(echo $SSH_CLIENT| awk -F' ' '{print $1}')
echo "# X/11 Display : $DISPLAY @--> $sshDisplayIp"
fi
;;
esac
}
####
# END FUNCTIONS
####
# First thing to do is establish a host where the RCS version of this file is available on demand
_rootCopyHost=addiction.spiritual-machines.org
_uname=$(uname)
_unameA=$(uname -a)
# Into information for user at beginning of login
echo "Starting shell initialization, please wait."
echo -n "Profile version: "
echo '$Revision: 1.10 $'
echo -n "Adjusting for platform: "
echo $_unameA
echo "Part 1: Setting numerous environmental variables..."
# NetCool License Server
export NCO_ELMHOST=polaris.noc.sgi.net
# SET BLOCKZIE FOR POSIX
# values can be '1k' or '1024'
echo "Setting POSIX blocksize..."
export BLOCKSIZE=1024
#Set remote X server based on SSH remote host
#Do not uncomment unless you are not using X11 forwarding on SSH
echo "Setting up X/11 DISPLAY..."
#export DISPLAY=`echo $SSH_CLIENT | cut -f1 -d ' '`:0
# Who the eff would think that the EMACS docs would ever be bigger than the binary
echo "Setting global EDITOR env..."
export EDITOR=vim
echo "Establishing prompt configuration..."
# Colors for a NewerNicer(r) bash prompt
# Greets to SteveK (shade) and to whomever he jacked them from
export COLOR1="\[\033[0;36m\]" # Dark Cyan
export COLOR2="\[\033[1;30m\]" # Light Black (grey maybe)
export COLOR3="\[\033[1;36m\]" # Light Cyan
export COLOR4="\[\033[0m\]" #
export COLOR5="\[\033[1;37m\]" # Light White
export COLOR6="\[\033[0;31m\]" # Red
export COLOR7="\[\033[0;35m\]" # Purple
export COLOR8="\[\033[1;31m\]" # Light Red
export COLOR9="\[\033[1;32m\]" # Light Green
export COLOR0="\[\033[0;32m\]" # Green
export COLORA="\[\033[1;34m\]" # Light Blue
export COLORB="\[\033[0;34m\]" # Blue
TTYLL="$(echo `tty` | sed 's/\/dev\///')"
# quickie chart colors
# Black 0;30m
# White 1;37m
# Blue 0;34m
# Light Blue 1;34m
# Green 0;32m
# Light Green 1;32m
# Cyan 0;36m
# Light Cyan 1;36m
# Red 0;31m
# Light Red 1;31m
# Purple 0;35m
# Pink 1;35m
# Brown 0;33m
# Yellow 1;33m
# Light Gray 0;37m
# Dark Gray 1;30m
# Decode how to setup the prompt based on X11 or not
# Don't use PROMPT_COMMAND if the terminal software is gonna barf (physical terms will barf)
case $TERM in
xterm*)
export PS1="$COLOR3[$COLOR7\d $COLOR3@ $COLOR7\@$COLOR3] $COLOR1\u$COLOR3($COLOR8$TTYLL$COLOR3)@$COLOR1\h$COLOR3[$COLOR6\$(getNumberOfJobs)$COLOR3][$COLOR0\!$COLOR3]$COLOR1:\$PWD$COLOR3($COLOR8\$(getDirDiskUsage)$COLOR3)\$$COLOR4 "
export PROMPT_COMMAND='export RSTATUS=$?; echo -ne "[$RSTATUS] "; export PS1; echo -ne "\033]0;${LOGNAME}@${HOSTNAME}:${PWD}\007"'
;;
ansi*)
export PROMPT_COMMAND='echo -ne "\033]0;${LOGNAME}@${HOSTNAME}:${PWD}\007"'
;;
*)
export PS1='[\d @ \@] \u@\h:$PWD\$ '
;;
esac
# Other prompts (some are debuggers)
echo "Setting other prompts..."
export PS2='more> '
export PS3
export PS4
#Set the path. Keep adding to this as Sun Microsystems and Linux ruin the unix directory structure
echo "Setting man paths..."
export PATH=~/bin:/opt/bin:/usr/local/sbin:/usr/local/bin:/usr/X/bin:/usr/x/bin:/usr/X11R6/bin:/usr/openwin/bin:/usr/dt/bin:/usr/ccs/bin:/usr/ucb:/usr/contrib/bin:/opt/SUNWspro/bin/:/opt/PGPcmdln/:/var/qmail/bin:/usr/pkg/bin:/usr/pkg/sbin:/usr/proc/bin:/opt/gnome/bin:/usr/bin:/bin:/usr/sbin:/sbin
# Man path (same trash talk about Sun and Linux here)
echo "Setting up man page paths..."
export MANPATH=/usr/pkg/man:/usr/local/man:/usr/share/man:/usr/man:/usr/X/man:/usr/X11R6/man:/usr/X11R5/man
# Compiling & Development settings here
# CLFAGS & Other Compiler Optimizations
echo "Setting up development environment and compiler optimizations..."
export LD_LIBRARY_PATH=/usr/lib:/lib:/usr/local/lib:/opt/gnome/lib:/usr/X11R6/lib:/usr/X/lib
#export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:/usr/pkg/lib/pkgconfig:/ysr/X11R6/lib/pkgconfig"
# old solaris h4x that were absolutely essential to using gnu gcc and
# binutils on 6,7,8,9
# export LDFLAGS="-ldl -lnsl -lsocket
_compilePathsInclude="-I/usr/include -I/usr/pkg/include -I/usr/local/include -I/usr/X11R6/include -I/usr/X/include"
_compilePathsLink="-L/usr/lib -L/usr/pkg/lib -L/usr/local/lib -L/usr/X11R6/lib -L/usr/X/lib"
#export LDFLAGS="$_compilePathsInclude $_compilePathsLink"
#export CFLAGS="$_compilePathsInclude $_compilePathsLink"
#export CPPFLAGS=""
#export CXXFLAGS=""
# this is needed for SSH aliases below
export SSHPATH=$(which ssh)
# BEING ALIASES (PART 2)
echo "Part 2: Setting numerous aliases..."
# Set all aliases
echo -n "Index: "
parseDFAlias
echo -n "df, "
alias tr="traceroute"
echo -n "tr, "
alias ls="ls -laF"
echo -n "ls, "
alias mx="nslookup -query-type=MX"
echo -n "mx, "
alias dir='ls -laF | grep "^d"'
echo -n "dir, "
# alias pine='pine.4.21'
# systems patched to 4.3 and renamed binary as per obiits/CMS case
# Long live Amber Wolfe
alias whois="whois -h whois.networksolutions.com"
echo -n "whois, "
# Some version of top don't check a termcap/term's $height
alias top="top 100"
echo -n "top, "
alias awhois="/usr/bin/whois -h whois.arin.net"
echo -n "awhois, "
alias screen="screen -T $TERM -c ~/.screenrc -e^Ff -s $SHELL"
echo -n "screen, "
#alias startx="clear & xinit -- -nolisten tcp & logout"
#echo -n "startx, "
alias ssh="$SSHPATH -2 -v"
echo -n "ssh, "
alias tarpipe="tar cvf - . | ( cd \!* ; tar xvf - )"
echo -n "tarpipe, "
alias pgrep="ps -ef|egrep -v -i egrep|grep -i"
echo -n "pgrep, "
alias rootdig="dig @l.gtld-servers.net ns"
echo -n "rootdig, "
alias arindig="dig @ARROWROOT.ARIN.NET ns"
echo -n "arindig, "
alias cwdig="dig @ns.cw.net ns"
echo -n "cwdig, "
alias sprintdig="dig @ns1-auth.sprintlink.net ns"
echo -n "sprintdig, "
alias seekup="scp -v ${_rootCopyHost}:~/.bash_profile ~"
echo -n "seekup, "
# need one final echo
echo "done."
echo "Setting aliases to lower process priority (nice @ +19): "
alias rar="nice -n 19 $(which rar)"
echo -n "rar, "
alias make="nice -n 19 $(which make)"
echo -n "make, "
alias killGnome="bonobo-slay; oaf-slay; pkill -9 oafd; pkill -9 gconf; pkill -9 bonobo; pkill -9 wombat; pkill -9 esd"
echo -n "killGnome, "
echo "done."
# This is a long story, but I don't think host(8) is the best option at the moment
case `uname` in
Linux*)
alias nslookup="host"
esac
# PART 3 -- GENERAL SETTINGS
echo "Part 3: General Settings..."
echo "Setting unmask value..."
umask 077
# print out nice stuff to keep you updated - top command sysV oriented - BSD version available in notes
echo "Disabling write(1) messages..."
# PINE cores enough on its own without the help of TTY crap
mesg n
# special logout script other than .bash_logout
trap '$HOME/.sh_logout; exit 0' EXIT
#Stop the slaughter!! Limit core files.
echo "Disabling core files..."
#ulimit -c 0
#Lastly and most importantly, source your local .bash_profile_local
if [ -f ~/.bash_profile_local ]; then
echo "Source'ing local bash profile..."
source ~/.bash_profile_local
else
echo "No local Bash profile to source..."
fi
# PART 4: Advanced BASH Settings
echo "Part 4: BASH Settings (readline,shopt,)..."
echo 'Legacy "set" options....'
echo "Enabling EMACS CLI Edit Mode..."
#set -o emacs
set -o vi
echo "Enabling EOF Exit..."
#set -o ignoreeof
echo "Disabling file clobber via I/O redirect..."
set -o noclobber
#set -o noglob
echo "Enabling file globbing..."
#set -o nounset
# MORE - ADJUST LATER
## allexport
## braceexpand
## errexit
## hashall
## histexpand
## keyword
## monitor
## noclobber
## noexec
## noglob
## notify
## nounset
## onecmd
## physical
## privileged
## verbose
## xtrace
## history
## ignoreeof
## interactive-comments
## posix
## emacs
## vi
echo 'Newer "shopt" Options...'
shopt -u cdable_vars
shopt -u cdspell
shopt -u checkhash
shopt -s checkwinsize
shopt -s cmdhist
shopt -u dotglob
shopt -u execfail
shopt -s expand_aliases
shopt -u extglob
shopt -u histreedit
shopt -u histappend
shopt -u histverify
shopt -s hostcomplete
shopt -u huponexit
shopt -s interactive_comments
shopt -u lithist
shopt -u mailwarn
shopt -u nocaseglob
shopt -u nullglob
shopt -s promptvars
shopt -u restricted_shell
shopt -u shift_verbose
shopt -s sourcepath
echo "Mail options..."
export MAILCHECK=10
echo "Setting new mail check interval to 10 seconds..."
export MAIL=/var/mail/lavalamp
export MAILPATH=$MAIL
echo "Setting mailbox path to $MAILPATH ..."
echo "History options..."
echo "Disabling duplicate history entries..."
export HISTCONTROL=ignoreboth
export HISTIGNORE=""
echo "Setting history ignore pattern to $HISTIGNORE ..."
export HISTFILE=~/.bash_history
echo "Setting command history file to $HISTFILE ..."
export HISTFILESIZE=750000
echo "Setting history database file size to $HISTFILESIZE ..."
export HISTSIZE=750000
echo "Setting history database memory size to $HISTSIZE ..."
echo "Setting FCEDIT to match EDITOR..."
export FCEDIT=$EDITOR
# PART 5
echo "Part 5: 3rd Party Utils..."
echo "Setting CVS Flags (NOTE: check ~/.cvsrc)..."
export CVS_OPTIONS="-z0 -t"
# Print a summary...
echo "Resetting terminal..."
clear
# reset $TERM
echo "########## SUMMARY REPORT ##########"
echo "# Hostname : $(hostname -s)"
echo "# Environment : $(uname -s)"
echo "# Release : $(uname -r)"
echo "# Revision : $(uname -v)"
echo "# Architecture : $(uname -p)"
echo "# Stepping : $(uname -m)"
echo "# Platform : $(uname -i)"
echo "# BASH Version : $BASH_VERSION"
echo "# UMASK : $(umask)"
echo "# Terminal : $TERM"
echo "# Editor : $EDITOR"
setUpX11
#echo "# X/11 Display : $DISPLAY"
echo "# Blocksize : $BLOCKSIZE"
echo "# Quota(blocks) : "
echo "# Usage(blocks) : "
echo "####################################"
#echo ""
#echo "####################################"
#echo "#### Top CPU usage processes: #####"
#echo "####################################"
#top -d 2 | col -b | head -n 10 | tail -4
echo "####################################"
echo "######### Current Users ###########"
echo "####################################"
w
echo "-------------------------------------------------------------------------------"
who
echo "-------------------------------------------------------------------------------"
finger
# clean up stale caches (might screw w/ other shells)
#find ~ -name ".curDirDiskUsage" | xargs rm
# DO NOT EDIT BELOW THIS POINT -- GNU RCS REVISION LOG FOLLOWS
#
# $Log: .bash_profile,v $
# Revision 1.10 2002/12/24 01:50:21 lavalamp
# added process list and...disk usage w/ smart caching to PS1 -lava
#
# Revision 1.9 2002/12/23 21:47:47 lavalamp
# whatever...do't remember -lava
#
# Revision 1.8 2002/12/11 22:03:01 lavalamp
# more cflags ldflags changes
# yay for broken toolchains -lava
#
# Revision 1.7 2002/12/11 20:09:19 lavalamp
# add PKG_CONFIG_PATH -lava
#
# Revision 1.6 2002/12/11 20:04:43 lavalamp
# whatever =/
#
# Revision 1.5 2002/03/24 05:04:58 lavalamp
# finally did my X/11 code, just needed to check some env's, that's all -lava
#
# Revision 1.4 2002/03/12 04:15:27 lavalamp
# More customization -- enough for now -lava
#
# Revision 1.3 2002/03/11 07:23:32 lavalamp
# More cosmetic fixes -lava
#
# Revision 1.2 2002/03/11 02:57:21 lavalamp
# new fixes -lava
#
# Revision 1.1 2002/03/11 01:52:13 lavalamp
# intial checkin
#
#