Skip to content

Instantly share code, notes, and snippets.

@sergio-fry
Created February 15, 2010 12:46
Show Gist options
  • Save sergio-fry/304615 to your computer and use it in GitHub Desktop.
Save sergio-fry/304615 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
def git_branch
(%x{git branch 2> /dev/null}.grep(/^\*/).first || '').gsub(/^\* ([a-z0-9_]+)[[:space:]]+$/i, '\1')
end
def set_color color
"\033[#{color}m"
end
def print_result result
print "#{set_color('37')}(#{result}#{set_color('37')}#{set_color('00')})"
end
if git_branch == 'master'
print_result "#{set_color('41')}#{set_color('32')}#{git_branch}"
elsif !git_branch.empty?
print_result "#{set_color('32')}#{git_branch}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment