/ Published in: Bash
                    
                                        
Improved version of http://snipplr.com/view/15246/color-coded-svn-status/
                
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
#!/usr/bin/python
"""
Author: Saophalkun Ponlu (http://phalkunz.com)
Contact: [email protected]
Date: May 23, 2009
Modified: June 15, 2009
"""
import sys
import re
import os
import subprocess
def getCommandParameters():
parameters = ''
for i in range(1, sys.argv.__len__()):
parameters += sys.argv[i] + " "
return parameters
def matchStatusColorAndPrint(line):
statusColors = {
"M": "31", # red
"\?": "32", # green
"A": "32", # green
"C": "30;41", # black on red
"-": "31",
"\+": "32",
}
for color in statusColors:
match = re.match(color, line)
if match:
os.popen("echo '\E[" + statusColors[color] + "m" + line + "\E[m'", 'w')
return True
os.popen("echo \"" + line + "\"", 'w')
def escapeSpecialChars(line):
return line.replace('$', '\$')
if __name__ == "__main__":
parameters = getCommandParameters();
output = subprocess.Popen('svn ' + parameters, shell=True, stdout=subprocess.PIPE);
while True:
line = output.stdout.readline()
if not line:
break
escapedLine = escapeSpecialChars(line.strip())
matchStatusColorAndPrint(escapedLine)
Comments
 Subscribe to comments
                    Subscribe to comments
                
                