Skip to content

Instantly share code, notes, and snippets.

@gonzalo-bulnes
Created September 30, 2014 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gonzalo-bulnes/ee0335a64a062e932211 to your computer and use it in GitHub Desktop.
Save gonzalo-bulnes/ee0335a64a062e932211 to your computer and use it in GitHub Desktop.
Bash configuration to get its prompt to display the current Git branch.
# ...
# Add these lines at the end of your ~/.bash_profile
# Git functions (used to define a custom 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)]/"
}
# Define a custom prompt which displays the current git branch,
# and a star if the branch holds uncommitted changes.
PS1='\u@\h:\w$(parse_git_branch)$ '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment