-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ... | |
# 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