Skip to content

Instantly share code, notes, and snippets.

@Ofanite
Created August 15, 2011 15:30
Show Gist options
  • Save Ofanite/1147002 to your computer and use it in GitHub Desktop.
Save Ofanite/1147002 to your computer and use it in GitHub Desktop.
My bash_profile
# .bash_profile
#
# This is a heavyweight bash profile, which makes your workstation more
# usable.
# Lion uses a derpy CC by default. This will fix that.
export CC=/usr/bin/gcc-4.2
# Pull in the whatever aliases you might have.
if [ -f $HOME/.aliases ] ; then
source $HOME/.aliases
fi
# Always vim, all the time, for everything.
export EDITOR=vim
# Pull in bash completion stuff so we get git status
# If you use macports, you'll want to sub in their stuff instead.
# If you don't use anything for the git bash stuff, get you something.
# You need it for this bashrc to work right.
if [ -f `brew --prefix`/etc/bash_completion ]; then
. `brew --prefix`/etc/bash_completion
fi
# Set the title bar to shorthost:curdir so that when you log out of
# a linux host you don't have the title bar still set to that host.
#
# Recipe for DISASTER.
case "$TERM" in
xterm*|rxvt*)
PROMPT_COMMAND='echo -ne "\033]0;${HOSTNAME%%.*} : ${PWD##*/}\007"'
;;
*)
;;
esac
# Some things I may want to be private, like amazon creds, but I want this
# profile to be distribuatable, so I put private stuff elsewhere.
if [ -f ~/.bash_private ] ; then
source ~/.bash_private
fi
# List of handy color escape sequences, properly escaped for Bash so they
# don't fuck up your line wraps.
txtblk='\[\033[0;30m\]' # Black - Regular
txtred='\[\033[0;31m\]' # Red
txtgrn='\[\033[0;32m\]' # Green
txtylw='\[\033[0;33m\]' # Yellow
txtblu='\[\033[0;34m\]' # Blue
txtpur='\[\033[0;35m\]' # Purple
txtcyn='\[\033[0;36m\]' # Cyan
txtwht='\[\033[0;37m\]' # White
bldblk='\[\033[1;30m\]' # Black - Bold
bldred='\[\033[1;31m\]' # Red
bldgrn='\[\033[1;32m\]' # Green
bldylw='\[\033[1;33m\]' # Yellow
bldblu='\[\033[1;34m\]' # Blue
bldpur='\[\033[1;35m\]' # Purple
bldcyn='\[\033[1;36m\]' # Cyan
bldwht='\[\033[1;37m\]' # White
undblk='\[\033[4;30m\]' # Black - Underline
undred='\[\033[4;31m\]' # Red
undgrn='\[\033[4;32m\]' # Green
undylw='\[\033[4;33m\]' # Yellow
undblu='\[\033[4;34m\]' # Blue
undpur='\[\033[4;35m\]' # Purple
undcyn='\[\033[4;36m\]' # Cyan
undwht='\[\033[4;37m\]' # White
bakblk='\[\033[40m\]' # Black - Background
bakred='\[\033[41m\]' # Red
badgrn='\[\033[42m\]' # Green
bakylw='\[\033[43m\]' # Yellow
bakblu='\[\033[44m\]' # Blue
bakpur='\[\033[45m\]' # Purple
bakcyn='\[\033[46m\]' # Cyan
bakwht='\[\033[47m\]' # White
txtrst='\[\033[m\]' # Text Reset
# Set up the prompt
export PS1="$txtgrn\h$bldylw:$txtgrn\w$txtpur\$$txtrst "
# I don't always write utility scripts, but when I do I put them in home/bin
export PATH=$HOME/bin:$PATH
# Everyone should use rvm.
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
# When you merge a branch, you should clean it up on origin
branch-cleanup() {
git checkout develop
git branch -D $1
git push origin :$1
}
# When you make a new branch, you'll probably want to track it remotely too.
branch-new() {
git checkout -b $1
git push -u origin $1
}
# These aliases are part of how this bashrc works, so they
# get to live here. Also, we should definitely not alias cd
# unless we're pretty sure the new one is going to work, so
# I'm gonna at least check to make sure we have bash-completion.
type __gitdir | grep -q function
if [[ $? == 0 ]] ; then
alias cd='git_aware_change_directory'
alias whereami='describe_environment'
else
echo "Your bash_profile wants bash-completion to work right."
fi
# This is a function for changing directories which does some git magic.
git_aware_change_directory() {
builtin cd $1
gitdir=$(__gitdir)
# Always use [[ and never [ because [ has some FUCKED syntax.
if [[ (${gitdir} == '') && (${GIT_REPO} != '') ]] ; then
# We're not in a git repo, but we just were, so let's set everything back
# to normal.
unset GIT_REPO
export PS1="$txtgrn\h$bldylw:$txtgrn\w$txtpur\$$txtrst "
elif [[ ((${gitdir} != '') && (${GIT_REPO} == '')) || ($GIT_REPO != `get_git_repo`) ]] ; then
# We just changed into a (new) git repo, we should set our variables accordingly
# and describe our new environment.
export GIT_REPO=`get_git_repo`
describe_environment
GIT_PS1_SHOWDIRTYSTATE=1
export PS1="$txtgrn\h$bldylw:$txtgrn\w$txtylw\$(__git_ps1 ' [%s]')$txtpur\$$txtrst "
fi
}
get_git_repo() {
# This would be a lot easier if __gitdir would just return a full path
# all the time.
if [[ $(__gitdir) == ".git" ]] ; then
REPO=`pwd`
else
REPO=$(__gitdir)
REPO=${REPO%/.git}
fi
echo $REPO
}
describe_environment() {
# Echo wants the same escape sequences, but the bash ones have to be escaped
# and the echo ones have to not be escaped, so guess I'm including all those twice.
etxtblk='\033[0;30m' # eblack - Regular
etxtred='\033[0;31m' # Red
etxtgrn='\033[0;32m' # Green
etxtylw='\033[0;33m' # Yellow
etxtblu='\033[0;34m' # eblue
etxtpur='\033[0;35m' # Purple
etxtcyn='\033[0;36m' # Cyan
etxtwht='\033[0;37m' # White
ebldblk='\033[1;30m' # Black - Bold
ebldred='\033[1;31m' # Red
ebldgrn='\033[1;32m' # Green
ebldylw='\033[1;33m' # Yellow
ebldblu='\033[1;34m' # Blue
ebldpur='\033[1;35m' # Purple
ebldcyn='\033[1;36m' # Cyan
ebldwht='\033[1;37m' # White
eundblk='\033[4;30m' # Black - Underline
eundred='\033[4;31m' # Red
eundgrn='\033[4;32m' # Green
eundylw='\033[4;33m' # Yellow
eundblu='\033[4;34m' # eblue
eundpur='\033[4;35m' # Purple
eundcyn='\033[4;36m' # Cyan
eundwht='\033[4;37m' # White
ebakblk='\033[40m' # Black - Backgroeund
ebakred='\033[41m' # Red
ebadgrn='\033[42m' # Green
ebakylw='\033[43m' # Yellow
ebakblu='\033[44m' # Blue
ebakpur='\033[45m' # Purple
ebakcyn='\033[46m' # Cyan
ebakwht='\033[47m' # White
etxtrst='\033[m' # Text Reset
# Now to announce ourselves a new git repo
echo -e "${etxtylw}---GIT REPO: $GIT_REPO${etxtrst}\n"
echo -e "${etxtpur}Ruby:${etxtrst} `which ruby`"
echo -e "${etxtpur}Version:${etxtrst} `ruby -v`"
# This can be handy, but it can also spew some mess, so I tend to leave it
# out. YMMV.
#echo -e "${etxtpur}Head:${etxtrst} `git show --pretty=oneline HEAD`"
echo -e "${etxtpur}Remotes:\n${etxtrst}`git remote -v show`"
if [ -f ${GIT_REPO}/Gemfile ] ; then echo -e "${etxtgrn}Gemfile is present, use bundle exec${etxtrst}" ; fi
echo -e "\n${etxtylw}------${etxtrst}"
git status
echo -e "${etxtylw}------${etxtrst}\n"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment