Last active
December 14, 2015 15:18
-
-
Save gdhaworth/5106486 to your computer and use it in GitHub Desktop.
Uses git-prompt.sh (bundled with git) to show a color-coded branch name and dirty status in the prompt text if executing within a Git repository.
This file contains 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
__colorize_arg () | |
{ | |
local color='' | |
case "$1" in | |
# Other options: AM, AM/REBASE, CHERRY-PICKING, BISECTING | |
*'|MERGING'* | *'|REBASE'*) # Merging or rebasing | |
color="0;31" # Red | |
;; | |
*'*+'*) # Unstaged + staged | |
color="1;35" # Purple | |
;; | |
*'*'*) # Unstaged | |
color="0;33" # Yellow | |
;; | |
*'+'*) # Staged | |
color="1;36" # Cyan | |
;; | |
*) | |
color="0;32" # Green | |
;; | |
esac | |
echo -e "\e[${color}m(${1})\e[m" | |
} | |
__git_branch_or_else () | |
{ | |
local branch="$(__git_ps1 '%s')" | |
[[ ! -z "$branch" ]] && echo "$(__colorize_arg """${branch}""")" || echo "$1" | |
} | |
source /opt/local/share/git-core/git-prompt.sh | |
GIT_PS1_SHOWDIRTYSTATE=1 | |
PS1='[$(__git_branch_or_else "\u@\h") \W]\$ ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment