Skip to content

Instantly share code, notes, and snippets.

@BrianMehrman
Created October 14, 2014 15:58
Show Gist options
  • Save BrianMehrman/b0698f0c29caf0478bc4 to your computer and use it in GitHub Desktop.
Save BrianMehrman/b0698f0c29caf0478bc4 to your computer and use it in GitHub Desktop.
git branch in bash prompt
# ----------------------------------------------------------------------
# PROMPT
# ----------------------------------------------------------------------
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit, working directory clean" ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/(\1$(parse_git_dirty))/"
}
LBLUE="\[\e[0;36m\]"
GREEN="\[\e[0;32m\]"
YELLOW="\[\e[0;33m\]"
VIOLAT="\[\e[0;94m\]"
PS_CLEAR="\[\e[0m\]"
export PS1="${YELLOW}[${GREEN}\u${LBLUE}@${VIOLAT}\h${YELLOW}][${LBLUE}\w${YELLOW}]\$(parse_git_branch) ♆${PS_CLEAR} "
@BrianMehrman
Copy link
Author

Add this to your .bash_profile in your user's root directory.

Then run source ~/.bash_profile to refresh.

When you cd into a directory with git you should see this.

[bmehrman@Mehrman-MBP]~/projects/vmi-ruby

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