我已经尝试了一个小的python脚本,在bin文件夹....
“gitprompt”文件< / p >
#!/usr/bin/env python
import subprocess, os
s = os.path.join(os.getcwd(), '.git')
def cut(cmd):
ret=''
half=0
record = False
for c in cmd:
if c == "\n":
if not (record):
pass
else:
break
if (record) and c!="\n":
ret = ret + c
if c=='*':
half=0.5
if c==' ':
if half == 0.5:
half = 1
if half == 1:
record = True
return ret
if (os.path.isdir(s)):
out = subprocess.check_output("git branch",shell=True)
print cut(out)
else:
print "-"