Created
April 19, 2010 15:36
-
-
Save jandot/371176 to your computer and use it in GitHub Desktop.
Add git branch to bash prompt. Green if OK; red if uncommitted changes or if ahead of master.
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
#Based on http://www.furmanek.net/39/unix-prompt-for-usage-with-git/ | |
green = "\033[0;32m" | |
reset = "\033[0m" | |
red = "\033[0;31m" | |
current_branch = `git branch 2>/dev/null`.grep(/^\*/).first | |
if current_branch | |
branch_name = current_branch.gsub(/^\*\s*/,'').strip | |
status_lines = `git status`.split(/\n/) | |
status = ( status_lines.length == 2 ) ? 'clean' : 'dirty' | |
color = ( status == 'clean' ) ? green : red | |
unless current_branch.empty? | |
print "#{color}(#{branch_name})#{reset}" | |
end | |
end | |
# Save as ~/git-ps.rb and put this in your .bashrc: | |
# parse_git_branch() { | |
# ruby ~/git-ps.rb 2>/dev/null | |
# } | |
# export PS1="[\w \$(parse_git_branch)]> " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment