Print Color-Coded SVN Status

I’ve been having difficulty in reading SVN status, which tells you which files in a project have been modified, added, or having a conflict with other developer’s changes. Status code in front of each line alone doesn’t help me quickly identifying one status code from another so I wrote a script to color code the lines with different colors according to their statuses. If you’re having the same issue, feel free to use the code below :)

#!/usr/bin/python
"""
 Author: Saophalkun Ponlu (http://phalkunz.com)
 Contact: phalkunz@gmail.com
 Date: May 23, 2009
"""


import sys, os, re

# add more status & color codes
colors = {
    "M": "31",      # red
    "\?": "32",     # green
    "C": "30;41"    # black on red
}

# build a paramter list
parameters = "";
for i in range(1, sys.argv.__len__()):
    parameters += sys.argv[i] + " ";

status = os.popen('svn st ' + parameters);
for line in status:
    passed = False
    # remove newline character from the line
    line = re.sub("\n", "", line)
   
    for color in colors:
        match = re.match(color+(" "*6), line)
        if match:  
            os.popen("echo '\E[" + colors[color] + "m" + line + "\E[m'", 'w')
            passed = True
    if(passed):
        continue
       
    os.popen("echo \"" + line + "\"", 'w')

1 Comment

  1. MyAvatars 0.2

    [...] Print Color-Coded SVN Status [...]

    Pingback by Daily News About Tech : A few links about Tech - Friday, 22 May 2009 19:41 — May 23, 2009 @ 2:42 pm

Leave a comment


*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word