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. Date: May 23, 2009
  5. Modified: June 15, 2009
  6. """
  7. import sys
  8. import re
  9. import os
  10. import subprocess
  11.  
  12. def getCommandParameters():
  13. parameters = ''
  14. for i in range(1, sys.argv.__len__()):
  15. parameters += sys.argv[i] + " "
  16. return parameters
  17.  
  18. def matchStatusColorAndPrint(line):
  19. statusColors = {
  20. "M": "31", # red
  21. "\?": "32", # green
  22. "A": "32", # green
  23. "C": "30;41", # black on red
  24. "-": "31",
  25. "\+": "32",
  26. }
  27. for color in statusColors:
  28. match = re.match(color, line)
  29. if match:
  30. os.popen("echo '\E[" + statusColors[color] + "m" + line + "\E[m'", 'w')
  31. return True
  32. os.popen("echo \"" + line + "\"", 'w')
  33.  
  34. def escapeSpecialChars(line):
  35. return line.replace('$', '\$')
  36.  
  37. if __name__ == "__main__":
  38. parameters = getCommandParameters();
  39. output = subprocess.Popen('svn ' + parameters, shell=True, stdout=subprocess.PIPE);
  40. while True:
  41. line = output.stdout.readline()
  42. if not line:
  43. break
  44. escapedLine = escapeSpecialChars(line.strip())
  45. matchStatusColorAndPrint(escapedLine)

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.