-
Notifications
You must be signed in to change notification settings - Fork 2
/
colored-svn
executable file
·94 lines (80 loc) · 1.94 KB
/
colored-svn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python
"""
Author: Saophalkun Ponlu (http://phalkunz.com)
Contact: [email protected]
Date: May 23, 2009
Modified: June 15, 2009
Additional modifications:
Author: Phil Christensen (http://bubblehouse.org)
Contact: [email protected]
Date: February 22, 2010
"""
import os, sys, re, subprocess
tabsize = 4
colorizedSubcommands = (
'status',
'st',
'add',
'remove',
'diff',
'update',
'up',
)
color = {
"black" : "30",
"red" : "31",
"green" : "32",
"brown" : "33",
"blue" : "34",
"violet" : "35",
"cyan" : "36",
"gray" : "37",
"darkGray" : "1;30",
"lightBlue" : "1;34",
"yellow" : "1;33",
"lightRed" : "1;31",
}
effects = {
"bold" : "1",
}
def on (c):
return ";"+str(10+int(color[c]));
statusColors = {
"M" : color["brown"],
"U" : "31",
"R" : color["blue"],
"G" : color["black"]+on("red"),
"\?" : color["lightRed"], # grey,
"\!" : color["red"],
"A" : color["green"],
"X" : color["red"],
"C" : color["black"]+on("cyan"),
"-" : color["red"],
"D" : color["yellow"],
"\+" : "32", # green
}
def colorize(line):
for color in statusColors:
if re.match(color, line):
return ''.join(("\033[", statusColors[color], "m", line, "\033[m"))
else:
return line
def escape(s):
s = s.replace('$', r'\$')
s = s.replace('"', r'\"')
s = s.replace('`', r'\`')
return s
passthru = lambda x: x
quoted = lambda x: '"%s"' % escape(x)
if __name__ == "__main__":
cmd = ' '.join(['svn']+[(passthru, quoted)[' ' in arg](arg) for arg in sys.argv[1:]])
output = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
cancelled = False
for line in output.stdout:
line = line.expandtabs(tabsize)
if(sys.argv[1] in colorizedSubcommands):
line = colorize(line)
try:
sys.stdout.write(line)
except:
sys.exit(1)