Color coded SVN status (v.2)


/ Published in: Bash
Save to your folder(s)

Improved version of http://snipplr.com/view/15246/color-coded-svn-status/


Copy this code and paste it in your HTML
  1. #!/usr/bin/python
  2. """
  3. Author: Saophalkun Ponlu (http://phalkunz.com)
  4. Contact: phalkunz@gmail.com
  5. Date: May 23, 2009
  6. Modified: June 15, 2009
  7. """
  8. import sys
  9. import re
  10. import os
  11. import subprocess
  12.  
  13. def getCommandParameters():
  14. parameters = ''
  15. for i in range(1, sys.argv.__len__()):
  16. parameters += sys.argv[i] + " "
  17. return parameters
  18.  
  19. def matchStatusColorAndPrint(line):
  20. statusColors = {
  21. "M": "31", # red
  22. "\?": "32", # green
  23. "A": "32", # green
  24. "C": "30;41", # black on red
  25. "-": "31",
  26. "\+": "32",
  27. }
  28. for color in statusColors:
  29. match = re.match(color, line)
  30. if match:
  31. os.popen("echo '\E[" + statusColors[color] + "m" + line + "\E[m'", 'w')
  32. return True
  33. os.popen("echo \"" + line + "\"", 'w')
  34.  
  35. def escapeSpecialChars(line):
  36. return line.replace('$', '\$')
  37.  
  38. if __name__ == "__main__":
  39. parameters = getCommandParameters();
  40. output = subprocess.Popen('svn ' + parameters, shell=True, stdout=subprocess.PIPE);
  41. while True:
  42. line = output.stdout.readline()
  43. if not line:
  44. break
  45. escapedLine = escapeSpecialChars(line.strip())
  46. matchStatusColorAndPrint(escapedLine)

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.