Skip to content

Instantly share code, notes, and snippets.

@woods
Created August 25, 2012 16:25
Show Gist options
  • Save woods/3467563 to your computer and use it in GitHub Desktop.
Save woods/3467563 to your computer and use it in GitHub Desktop.
My custom bash prompt
#!/bin/bash
#
# Scott Woods's custom bash prompt.
#
# Load this file by adding the following to the bottom of your ~/.bashrc:
#
# function prompt_command {
# export PS1=$(~/.prompt.bash)
# }
# export PROMPT_COMMAND='export LAST_RETURN_VALUE=$? ; prompt_command'
Red='\[\e[0;31m\]'
White='\[\e[0;37m\]'
Color_Off='\[\e[0m\]'
git_revision=$(git show 2> /dev/null | head -1 | awk '{ print substr($2,0,7) }')
if [ "$git_revision" ] ; then
git_revision=" | ${git_revision}"
if [ "$GIT_AUTHOR_NAME" ] ; then
git_author=" | $GIT_AUTHOR_NAME"
else
git_author=""
fi
git_branch_ref=$(git symbolic-ref HEAD 2> /dev/null)
if [ "$git_branch_ref" ] ; then
git_branch=" | ${git_branch_ref#refs/heads/}"
else
git_branch=" | [none]"
fi
git_clean=$(git status | grep "working directory clean")
if [ "$git_clean" ] ; then
git_status=""
else
git_status="*"
fi
git_info="${git_author}${git_revision}${git_branch}${git_status}"
else
git_info=""
fi
if [[ $LAST_RETURN_VALUE -eq 0 ]] ; then
dollar="\$"
else
dollar="${Red}\$${Color_Off}"
fi
path="\w"
command_number="[\!]"
echo "\n${White}${path}${git_info}\n${command_number}${Color_Off} ${dollar} "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment