Skip to content

Instantly share code, notes, and snippets.

@andyferra
Created February 22, 2009 00:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andyferra/68269 to your computer and use it in GitHub Desktop.
Save andyferra/68269 to your computer and use it in GitHub Desktop.
prompt with git branch and working directory
## ~/git-ps1.rb
green = "\033[0;32m"
red = "\033[0;31m"
base = "\033[0;37m" # <-- Needs to be set to whatever your shell base colors is
current_branch = `git branch 2>/dev/null`.grep(/^\*/).first
if current_branch
branch_name = current_branch.gsub(/^\*\s*/,'').strip
color = branch_name =~ /master/ ? green : red
puts "#{color}[#{branch_name}]#{base}" unless current_branch.empty?
end
## ~/.ps
parse_git_branch() {
ruby ~/git-ps1.rb
}
export PS1="\n\w \$(parse_git_branch)\n$ "
## add this to ~/.bash_profile, ~/.bashrc, etc.
. ~/.ps
# git branch via http://www.furmanek.net/39/unix-prompt-for-usage-with-git/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment