Created
July 23, 2013 16:04
-
-
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] >>
This file contains hidden or 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
# 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 |
This file contains hidden or 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
#!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