This is my first try at this, and very much a learning experience. Mostly a grab bag of stuff I found on this site, built around the default ubuntu .bashrc. Calls my .aliases file.
NOTE: I am still trying to get bash to share history among concurrent sessions. PROMPT_COMMAND='history -a; history -n' is not doing it for me.
## ~./bashrc ##
# a learning experience
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for more examples
# This is not an interactive shell. Begone!
[ -z '$PS1' ] && return
## environment variables ##
# Connect to emacs if it's running, or start a new instance
# Did you add (server-start) to your ~/.emacs file?
export EDITOR='emacsclient -n' ALTERNATE_EDITOR='emacs' VISUAL='emacsclient'
## bash history ##
# Decent sized history
HISTSIZE=2500
HISTFILESIZE=2500
# Don't put duplicate lines in the history...
export HISTCONTROL=ignoredups
# ... and ignore same sucessive entries...
export HISTCONTROL=ignoreboth
# ... and ignore ls and cd (if they are called without arguments), and bg,
# fg, exit, and clear, _and_ any command prefaced with a space
export HISTIGNORE='&:clear:ls:cd:[bf]g:exit:[ t\]*'
# Append history instead of overwriting...
shopt -s histappend
# ... and append and re-read the history every time a prompt is displayed
PROMPT_COMMAND='history -a; history -n'
## some shopt options ##
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# correct minor spelling errors in cd
shopt -s cdspell
#include dotfiles in wildcard expansion, and match case-insensitively
shopt -s dotglob
shopt -s nocaseglob
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(lesspipe)"
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color) color_prompt=yes;;
esac
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_colored_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"'
;;
*)
;;
esac
## tab completion ##
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
CDPATH=..:.:/:~:/media/bottom-drawer
## aliases ##
if [ -f ~/.aliases ]; then
. ~/.aliases
fi
## functions ##
function extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) rar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
function psgrep() {
if [ ! -z $1 ] ; then
echo "Grepping for processes matching $1..."
ps aux | grep $1 | grep -v grep
else
echo "!! Need name to grep for"
fi
}
# cd and ls
function cl {
case $1 in
-) cd -;ls;return;;
-*) local o=$1; shift;;
esac
cd $* && ls $o
}
# pushd to a specified package's documentation directory and ls it
function doc
{
pushd "/usr/share/doc/$1" && ls
}
## welcome message ##
echo -ne "Morning, boss. It's "; date '+%A, %B %-d %Y'
uptime
echo -e ""; cal
echo -e "And now your moment of Zen:"; fortune