-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmlterm-colors.py
executable file
·138 lines (126 loc) · 5.29 KB
/
mlterm-colors.py
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env python
# encoding: utf-8
import os
import shutil
import argparse
import re
import subprocess
def get():
"Get colorschames"
if not os.path.exists(os.path.expanduser('~/.mlterm/colorschames')):
os.makedirs(os.path.expanduser('~/.mlterm/colorschames'))
if os.path.exists('/tmp/mlterm-temp'):
shutil.rmtree('/tmp/mlterm-temp')
subprocess.call('git clone --depth 1 https://github.com/Ahed91/rtlize --branch master --single-branch /tmp/mlterm-temp', shell=True)
data_folder = '/tmp/mlterm-temp/mlterm/colorschames'
dest_folder = os.path.expanduser('~/.mlterm/colorschames')
for _ in os.listdir(data_folder):
__ = os.path.join(data_folder, _)
shutil.copy(__, dest_folder)
def check_color(color):
colorschame_list = os.listdir(os.path.expanduser('~/.mlterm/colorschames'))
legal_color = False
for idx, item in enumerate(colorschame_list):
if color == item :
legal_color = True
return colorschame_list[idx], legal_color
item = item.lower()
if color == item :
legal_color = True
return colorschame_list[idx], legal_color
item = item.upper()
if color == item :
legal_color = True
return colorschame_list[idx], legal_color
item = item.replace('.COLOR', '')
if color == item :
legal_color = True
return colorschame_list[idx], legal_color
item = item.lower()
if color == item :
legal_color = True
return colorschame_list[idx], legal_color
item = item.replace(item[0], item[0].upper())
if color == item :
legal_color = True
return colorschame_list[idx], legal_color
return 'none',legal_color
def set_color(name):
colors_path = os.path.expanduser('~/.mlterm/colorschames')
main_path = os.path.expanduser('~/.mlterm/main')
color_path = os.path.join(colors_path, name)
with open(color_path, 'r') as f :
data = f.readlines()
with open(os.path.expanduser('~/.mlterm/color'), 'w') as f :
f.writelines(data[0:16])
D = {}
for i,item in enumerate(data[16:23]):
D[i] = item
with open(main_path, 'r') as f :
lines = f.readlines()
with open(main_path, 'w') as f :
for line in lines:
if re.findall('^fg_color.*', line):
f.write(re.sub('^fg_color.*',D.pop(0).replace('\n','') , line))
continue
if re.findall('^bg_color.*', line):
f.write(re.sub('^bg_color.*',D.pop(1).replace('\n','') , line))
continue
if re.findall('^cursor_bg_color.*', line):
f.write(re.sub('^cursor_bg_color.*',D.pop(2).replace('\n','') , line))
continue
if re.findall('^cursor_fg_color.*', line):
f.write(re.sub('^cursor_fg_color.*',D.pop(3).replace('\n','') , line))
continue
if re.findall('^bd_color.*', line):
f.write(re.sub('^bd_color.*',D.pop(4).replace('\n','') , line))
continue
if re.findall('^it_color.*', line):
f.write(re.sub('^it_color.*',D.pop(5).replace('\n','') , line))
continue
if re.findall('^ul_color.*', line):
f.write(re.sub('^ul_color.*',D.pop(6).replace('\n','') , line))
continue
if re.findall('^#fg_color.*', line):
f.write(re.sub('^#fg_color.*',D.pop(0).replace('\n','') , line))
continue
if re.findall('^#bg_color.*', line):
f.write(re.sub('^#bg_color.*',D.pop(1).replace('\n','') , line))
continue
if re.findall('^#cursor_bg_color.*', line):
f.write(re.sub('^#cursor_bg_color.*',D.pop(2).replace('\n','') , line))
continue
if re.findall('^#cursor_fg_color.*', line):
f.write(re.sub('^#cursor_fg_color.*',D.pop(3).replace('\n','') , line))
continue
if re.findall('^#bd_color.*', line):
f.write(re.sub('^#bd_color.*',D.pop(4).replace('\n','') , line))
continue
if re.findall('^#it_color.*', line):
f.write(re.sub('^#it_color.*',D.pop(5).replace('\n','') , line))
continue
if re.findall('^#ul_color.*', line):
f.write(re.sub('^#ul_color.*',D.pop(6).replace('\n','') , line))
continue
if re.findall('^wall_picture.*', line):
f.write(line.replace('~', os.path.expanduser('~')))
continue
f.write(line)
for _ in D.keys():
f.write(D[_])
def main():
"""Execute"""
# Parser Options
parser = argparse.ArgumentParser()
parser.add_argument('-c','--colorschame', help="choose colorschame to apply on mlterm")
#parser.add_argument('--pic', help="set wallpaper for mlterm", action="store_true")
args = parser.parse_args()
if not os.path.exists(os.path.expanduser('~/.mlterm/colorschames')):
get()
[name,legal]=check_color(args.colorschame)
if not legal:
print 'Invalid or Unavailable Colorschame Name '
if legal:
set_color(name)
if __name__ == '__main__':
main()