Skip to content

Instantly share code, notes, and snippets.

@jeffjohnson9046
Last active April 12, 2017 22:26
Show Gist options
  • Save jeffjohnson9046/fd3e24dde6b2b5881af8288d6476e368 to your computer and use it in GitHub Desktop.
Save jeffjohnson9046/fd3e24dde6b2b5881af8288d6476e368 to your computer and use it in GitHub Desktop.
Command prompt that shows current git branch
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