I shortened my bash prompt (using the code at line 120 in my bashrc):
PS1='\u:\W\$ '
Now I wanna add the colored git branch to the shortened prompt, so that when the branch has uncommitted changes, it's shown in red and if the working directory is clean (nothing to commit) then the branch is showed in green.
Thank you!
Best Answer
This Github Gist by srguiwiz shows a prompt with colours based on branch status:
You only need to use
$(markup_git_branch $(git_branch))
in your prompt, wherever you want show the commit status and branch.There's a slight change to original code here: the
\033[0;30m
at the end should be\033[0;0m
to reset the prompt colour. The former sets it black, the latter resets formatting on the text.srguiwiz's code seems to have some problems, jcgoble3 made a better version: