Skip to content

Instantly share code, notes, and snippets.

@aki237
Last active August 29, 2015 14:24
Show Gist options
  • Save aki237/b7195819284a3392353d to your computer and use it in GitHub Desktop.
Save aki237/b7195819284a3392353d to your computer and use it in GitHub Desktop.
Enhanced bash prompt style with git information in it
PS1='\[\033[01;32m\]└──[\[\033[00m\]\[\033[01;31m\]\w\[\033[00m\]\[\033[01;32m\]]──[\[\033[00m\]\[\033[01;34m\]ѱ \[\033[00m\]$(gitp)\[\033[01;32m\]]──[\[\033[00m\]$(gits)\[\033[01;32m\]]\[\033[00m\]\n \[\033[01;32m\]└──>\[\033[00m\] '
#!/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)
if cut(out)=="master":
print "\033[01;34m"+cut(out)+"\033[00m"
else:
print "\033[01;33m"+cut(out)+"\033[00m"
else:
print "-"
#!/usr/bin/env python
import subprocess, os
s = os.path.join(os.getcwd(), '.git')
prompts = '\033[01;32mm:\033[00m'
modified = []
if (os.path.isdir(s)):
out = subprocess.check_output("git status",shell=True)
if "modified" in out :
out = subprocess.check_output("git status | grep 'modified'",shell=True)
out = out.split("\tmodified: ")
for afile in out:
afile = afile.replace("\n","")
if afile == "":
pass
else :
afile = "\033[01;31m"+afile+"\033[00m"
modified.append(afile)
for afile in modified :
prompts = prompts + afile + " "
prompts = prompts[:-1]
print prompts
else:
stat = subprocess.check_output("git status",shell=True)
if "up-to-date" in stat :
print "\033[01;32mUp to Date\033[00m"
elif "ahead" in stat and "3" in stat:
out = subprocess.check_output("git push -u origin master",shell=True)
print "\033[01;32mUp to Date\033[00m"
else:
print "-"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment