Skip to content

Instantly share code, notes, and snippets.

@alex-sysoev
Forked from gonzalo-bulnes/.bash_profile
Created February 1, 2017 12:06
Show Gist options
  • Save alex-sysoev/1d63dc5a7d3e1a26d24046ecf5b256ea to your computer and use it in GitHub Desktop.
Save alex-sysoev/1d63dc5a7d3e1a26d24046ecf5b256ea 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