#!/bin/bash
# custom bashrc for easier sharing
# place local changes in ~/.mybashrc.local
# exit if non-interactive shell
[ -z "$PS1" ] && return
# set a lower umask
umask 0023
# use vim as my editor
export EDITOR="/usr/bin/vim"
# grep colors
export GREP_COLOR="1;37;41"
# set my LANG
export LANG=en_US.UTF-8
export LC_ALL=en_US.utf8
# fix up multiple history files based on tty
export SHELLID=$(tty | set 's!/!.!g')
export HISTFILE=${HISTFILE}${SHELLID}
# settings for history
export HISTIGNORE="&:bg:fg:pwd:jobs:reset:shutdown"
export HISTCONTROL="ignoreboth:erasedups"
export HISTSIZE=5000
export HISTFILESIZE=5000
# append to the history instead of overwrite
shopt -s histappend
# use vi keys
set -o vi
# notify of completed jobs immediately
set -o notify
# no coredumps
ulimit -c 0
# don't allow redirects to overwrite existing files by default
# force using: ls /etc >| output.txt
set -o noclobber
# don't exit shell on eof
set -o ignoreeof
# fix typos in cd commands
shopt -s cdspell
# spell correct on dir names
shopt -s dirspell
# keep lines and columns updated
shopt -s checkwinsize
# use egrep style matching: ls -d !(*.bak|*.orig)
shopt -s extglob
# save multi-line commands in history on a single line
shopt -s cmdhist
# automatically rehash
shopt -s checkhash
# force source to the current dir instead of the PATH
shopt -u sourcepath
# bash 4 features
if [[ ${BASH_VERSINFO[0]} -ge 4 ]]; then
# allow ** in expansion to match directories
shopt -s globstar
# auto cd into a typed dir
shopt -s autocd
fi
# get .mybashrclib into env
if [ -f "$HOME/.mybashrclib" ]; then
. $HOME/.mybashrclib
fi
# get .mybashaliases into env
if [ -f "$HOME/.mybashaliases" ]; then
. $HOME/.mybashaliases
fi
# get colors for LS
have dircolors && eval $(dircolors -b)
# set prompt colors (vars from .mybashrclib)
BLACK=$black
RED=$red
GREEN=$green
YELLOW=$yellow
BLUE=$blue
PURPLE=$purple
CYAN=$cyan
WHITE=$white
# add personal bin dir to path (start with $PATH, then use $MYPATH on the rest)
MYPATH=$(_path "${HOME}/bin" "$PATH" "prepend")
# add sbin dirs to path
MYPATH=$(_path "/sbin" "$MYPATH")
MYPATH=$(_path "/usr/sbin" "$MYPATH")
MYPATH=$(_path "/usr/local/sbin" "$MYPATH")
# custom prompt (vcp function in .mybashrclib)
MYPS1="${ENDC}[\A][\u@\[${GREEN}\]\h\[${ENDC}\]]\$(vcp)[\[${CYAN}\]\w\[${ENDC}\]]"
MYPS2="[\[${RED}\]sub shell\[${ENDC}\]]"
export PS1="${MYPS1}\n\$ "
export PS2="${MYPS1}${MYPS2}\n\$ "
# set some pager defaults
have less && export PAGER='less'; export LESS='-RS#3NM~g';
# fix up issues with xon/xoff
if [[ "$TERM" != "linux" ]]; then
# only run if stdin is a terminal
if [ -t 0 ]; then
stty -ixon -ixoff 2>/dev/null
fi
fi
# export MYPATH to PATH to get all the additions
export PATH=$MYPATH
# cleanup various vars we used
cleanup "MYPS1" "MYPS2" "MYPATH"
# a function to run on exit just in case
function _exit() {
# noop for now
:
}
# trap exit signals
trap _exit INT TERM EXIT
#############################################
# custom settings in .mybashrc.local
#############################################
if [ -e $HOME/.mybashrc.local ]; then
. $HOME/.mybashrc.local
fi