Skip to content

Instantly share code, notes, and snippets.

@vanhalt
Created July 23, 2013 16:04
Show Gist options
  • Save vanhalt/6063637 to your computer and use it in GitHub Desktop.
Save vanhalt/6063637 to your computer and use it in GitHub Desktop.
Git branch in the bash prompt (PS1) OS X. My goal was not to use bash it or oh-my-zsh :) With this script your prompt shell will end like this: ~/my_name/a_dir_with_a_git_project [current_git_branch_name] >>
# Your stuffs
PATH="$PATH:/Users/your_name/bin" # add the python script to your path
PS1='\w [$(git_branch)] >> ' # the magic are the single quotes ;)
# more of your stuffs
#!usr/bin/python
import subprocess
import sys
branches = subprocess.Popen(["git", "branch"], stdout = subprocess.PIPE, stderr = subprocess.STDOUT).communicate()[0]
name = '-'
for branch in branches.split("\n"):
if branch.find('*') > -1:
name = branch.split('*')[-1].strip()
sys.stdout.write(name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment