Last active
April 12, 2017 22:26
-
-
Save jeffjohnson9046/fd3e24dde6b2b5881af8288d6476e368 to your computer and use it in GitHub Desktop.
Command prompt that shows 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
GREEN='\[\033[0;32m\]' | |
YELLOW='\[\033[0;33m\]' | |
NC='\[\033[0m\]' # No Color | |
function parse_git_dirty { | |
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit, working tree clean" ]] && echo "*" | |
} | |
function parse_git_branch { | |
ref=$(git symbolic-ref HEAD 2> /dev/null) || return | |
echo "("${ref#refs/heads/}"$(parse_git_dirty))" | |
} | |
PS1="[\u@\h:\w ${GREEN}\$(parse_git_branch)${NC}] $ " | |
# Example (clean branch, no outstanding changes): | |
# [jeffjohnson@Jeffs-MBP:~/dev/sbac/git/repositories/microservices/TDS_ExamService (develop)] $ | |
# Example (dirty branch, some files have changed): | |
# [jeffjohnson@Jeffs-MBP:~/dev/sbac/git/repositories/microservices/TDS_ExamService (develop*)] $ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment