Created
August 20, 2012 17:37
-
-
Save johnpbloch/3406013 to your computer and use it in GitHub Desktop.
Display the current git branch in your command prompt. Add an asterisk if there are unstaged updates.
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
# Will produce command line prompts like | |
# directory(branch) $ | |
# in git repositories and like | |
# directory $ | |
# elsewhere. | |
# If there are unstaged changes in the repository, there will be an asterisk next to the branch name: | |
# directory(branch*) $ | |
parse_git_branch() { | |
hasmod="" | |
if [[ `git ls-files -dmo --exclude-standard 2> /dev/null` ]]; then | |
hasmod="*" | |
fi | |
git branch 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/(\1$hasmod)/" | |
} | |
export PS1="\W\$(parse_git_branch) $ " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment