Skip to content

Instantly share code, notes, and snippets.

@johncalistro
Created January 10, 2014 18:42
Show Gist options
  • Save johncalistro/8360105 to your computer and use it in GitHub Desktop.
Save johncalistro/8360105 to your computer and use it in GitHub Desktop.
Bash Prompt with Ruby version, Rails version, folder info, branch name and branch status
function _git_prompt() {
local git_status="`/usr/local/git/bin/git status -unormal 2>&1`"
if ! [[ "$git_status" =~ Not\ a\ git\ repo ]]; then
if [[ "$git_status" =~ nothing\ to\ commit ]]; then
local ansi=32
elif [[ "$git_status" =~ nothing\ added\ to\ commit\ but\ untracked\ files\ present ]]; then
local ansi=33
else
local ansi=35
fi
if [[ "$git_status" =~ On\ branch\ ([^[:space:]]+) ]]; then
branch=${BASH_REMATCH[1]}
test "$branch" != master || branch=' '
else
# Detached HEAD. (branch=HEAD is a faster alternative.)
branch="(`git describe --all --contains --abbrev=4 HEAD 2> /dev/null ||
echo HEAD`)"
fi
echo -n '\[\e[0;37;'"$ansi"';1m\]'"$branch"'\[\e[0m\] '
fi
}
function ruby_version() {
rvm current
}
function rails_version() {
rails=$(rails --version | grep '^Rails [0-9]')
if [ "$?" == "0" ]; then
echo $rails
else
echo "No rails"
fi
}
function _prompt_command() {
PS1='\[\e[0;23m\]`ruby_version` \[\e[0;23m\]`rails_version`  \[\e[0;31m\]\w \[\e[0m\]'"`_git_prompt`"'\n\$ '
}
PROMPT_COMMAND=_prompt_command
@johncalistro
Copy link
Author

Just copy to your .bash_profile, you can see the screenshot here http://cl.ly/image/04463g1L3H1T

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment