-
Notifications
You must be signed in to change notification settings - Fork 0
/
chameleon.py
executable file
·227 lines (177 loc) · 8.05 KB
/
chameleon.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/usr/bin/env python
from sys import argv
import os
import re
import serial
import sqlite3
rofi = ""
dir_path = os.path.dirname(os.path.realpath(__file__))
home_dir = os.path.expanduser("~")
def applyRazer(r, g, b):
os.system(
"echo -n -e \"\\x%s\\x%s\\x%s\" > /sys/bus/hid/drivers/razerkbd/0003:1532:0209.0003/matrix_effect_static"
% (r, g, b))
def applyi3(primary, secondary, background):
i3conf = open("%s/.config/i3/config" % home_dir).read()
i3conf = re.sub(r"set \$color #.{1,6}", "set $color #%s" % primary, i3conf)
i3conf = re.sub(r"set \$color_uf #.{1,6}", "set $color_uf #%s" % secondary,
i3conf)
i3conf = re.sub(r"set \$color_2 #.{1,6}", "set $color_2 #%s" % background,
i3conf)
with open("%s/.config/i3/config" % home_dir, 'w') as file:
file.write(i3conf)
def applyPolybar(primary, secondary, background):
polybarConf = open("%s/.config/polybar/config" % home_dir).read()
polybarConf = re.sub(r"primary = #.{1,6}", "primary = #%s" % primary,
polybarConf)
polybarConf = re.sub(r"secondary = #.{1,6}", "secondary = #%s" % secondary,
polybarConf)
polybarConf = re.sub(r"background = #.{1,6}",
"background = #%s" % background, polybarConf)
polybarConf = re.sub(r"secondary = #.{1,6}", "secondary = #%s" % secondary,
polybarConf)
with open("%s/.config/polybar/config" % home_dir, 'w') as file:
file.write(polybarConf)
def applyCava(primary):
cavaConf = open("%s/.config/cava/config" % home_dir).read()
cavaConf = re.sub(r"foreground = '#.{1,6}'",
"foreground = '#%s'" % primary, cavaConf)
with open("%s/.config/cava/config" % home_dir, 'w') as file:
file.write(cavaConf)
def applyRofi(primary, secondary):
rofiConf = open("%s/.Xdefaults" % home_dir).read()
rofiConf = re.sub(r"rofi.color-normal: .+",
"rofi.color-normal: #111111,#%s,#222222,#444444,#%s" %
(primary, primary), rofiConf)
rofiConf = re.sub(r"rofi.color-urgent: .+",
"rofi.color-urgent: #111111,#%s,#222222,#444444,#%s" %
(secondary, primary), rofiConf)
rofiConf = re.sub(r"rofi.color-active: .+",
"rofi.color-active: #111111,#%s,#222222,#444444,#%s" %
(secondary, primary), rofiConf)
with open("%s/.Xdefaults" % home_dir, 'w') as file:
file.write(rofiConf)
def applyTerm(red, green, blue):
with open("%s/.gtcolors" % home_dir, 'w') as file:
file.write("rgb(%d,%d,%d)\nrgb(%d,%d,%d)" %
(red[0], green[0], blue[0], red[2], green[2], blue[2]))
def applyFish(primary, secondary):
colors = [
"main %s" % primary, "command %s" % primary, "quote %s" % secondary,
"redirection %s" % primary, "end %s" % secondary, "param %s" % primary,
"comment %s" % secondary, "match %s" % secondary,
"search_match %s" % secondary, "operator %s" % primary,
"escape %s" % secondary, "cwd %s" % primary,
"autosuggestion %s" % secondary
]
for color in colors:
os.system("fish -c \"set -Ux fish_color_%s\"" % color)
def applyLed(red, green, blue):
with serial.Serial("/dev/ttyACM0") as ser:
ser.write(b"0 %d %d %d\n" % ((255 - red), (255 - green), (255 - blue)))
def applyTwmn(primary, background):
twmnConf = open("%s/.config/twmn/twmn.conf" % home_dir).read()
twmnConf = re.sub(r"foreground_color=#.{1,6}",
"foreground_color=#%s" % primary, twmnConf)
twmnConf = re.sub(r"background_color=#.{1,6}",
"background_color=#%s" % background, twmnConf)
with open("%s/.config/twmn/twmn.conf" % home_dir, 'w') as file:
file.write(twmnConf)
def applyi3lock(primary, primary2):
i3lockConf = open("%s/src/BlurLocker/lock.sh" % home_dir).read()
i3lockConf = re.sub(r"COLOR='#.{1,6}'", "COLOR='#%s'" % primary,
i3lockConf)
i3lockConf = re.sub(r"COLOR2='.{1,3}'", "COLOR2='%s'" % primary2,
i3lockConf)
with open("%s/src/BlurLocker/lock.sh" % home_dir, 'w') as file:
file.write(i3lockConf)
def applyFirefox(primary, secondary, background):
db = sqlite3.connect(
"%s/.mozilla/firefox/mg23unpc.dev-edition-default/stylish.sqlite" %
home_dir)
cr = db.cursor()
cr.execute("SELECT code FROM styles WHERE name = 'Auto';")
autoStyle = cr.fetchone()[0]
autoStyle = re.sub(r"--foreground: #.{1,6};",
"--foreground: #%s;" % primary, autoStyle)
rofiConf = re.sub(r"--foreground-alt: #.{1,6};",
"--foreground-alt: #%s;" % secondary, autoStyle)
rofiConf = re.sub(r"--background: #.{1,6};",
"--background: #%s;" % background, autoStyle)
cr.execute(
"UPDATE styles SET code = '%s' WHERE name = 'Auto';" % autoStyle)
db.commit()
db.close()
def applyCmus(red, green, blue):
primary = (36 * round(red[0] / 51)) + (6 * round(green[0] / 51)) + round(
blue[0] / 51) + 16
secondary = (36 * round(red[1] / 51)) + (6 * round(green[1] / 51)) + round(
blue[1] / 51) + 16
background = (36 * round(red[2] / 51)) + (
6 * round(green[2] / 51)) + round(blue[2] / 51) + 16
colors = [
"cmdline_fg=%d" % primary, "info=%d" % primary,
"separator=%d" % primary, "statusline_fg=%d" % primary,
"titleline_fg=%d" % primary, "win_cur=%d" % primary,
"win_cur_sel_bg=%d" % secondary, "win_cur_sel_fg=%d" % primary,
"win_dir=%d" % primary, "win_fg=%d" % primary,
"win_inactive_cur_sel_fg=%d" % primary,
"win_inactive_sel_fg=%d" % primary, "win_sel_bg=%d" % secondary,
"win_sel_fg=%d" % primary, "win_title_fg=%d" % primary,
"cmdline_bg=%d" % background, "statusline_bg=%d" % background,
"titleline_bg=%d" % background, "win_bg=%d" % background,
"win_inactive_cur_sel_bg=%d" % background,
"win_inactive_sel_bg=%d" % background, "win_title_bg=%d" % background
]
cmusConf = open("%s/.config/cmus/auto.theme" % home_dir).read()
for color in colors:
cmusConf = re.sub(r"set color_%s=.{1,3}" % color.split("=")[0],
"set color_%s" % color, cmusConf)
with open("%s/.config/cmus/auto.theme" % home_dir, 'w') as file:
file.write(cmusConf)
def main():
red = [int(argv[1][:2], 16), int(argv[2][:2], 16), int(argv[3][:2], 16)]
green = [
int(argv[1][2:4], 16), int(argv[2][2:4], 16), int(argv[3][2:4], 16)
]
blue = [
int(argv[1][4:6], 16), int(argv[2][4:6], 16), int(argv[3][4:6], 16)
]
primaryCode = (36 * round(red[0] / 51)) + (6 * round(green[0] / 51)) + round(
blue[0] / 51) + 16
secondaryCode = (36 * round(red[1] / 51)) + (6 * round(green[1] / 51)) + round(
blue[1] / 51) + 16
backgroundCode = (36 * round(red[2] / 51)) + (
6 * round(green[2] / 51)) + round(blue[2] / 51) + 16
print("Applying to keyboard")
applyRazer(argv[1][:2], argv[1][2:4], argv[1][4:])
print("Applying to i3")
applyi3(argv[1], argv[2], argv[3])
# print("Applying to Polybar")
# applyPolybar(argv[1], argv[2], argv[3])
print("Applying to rofi")
applyRofi(argv[1], argv[2])
print("Applying to fish")
applyFish(argv[1], argv[2])
print("Applying to gnome_terminal")
applyTerm(red, green, blue)
print("Applying to Firefox")
applyFirefox(argv[1], argv[2], argv[3])
print("Applying to cava")
applyCava(argv[1])
# print("Applying to twmn")
# applyTwmn(argv[1], argv[3])
print("Applying to cmus")
applyCmus(red, green, blue)
print("Applying to i3lock")
applyi3lock(argv[1], primaryCode)
print("Reloading Everything")
os.system("%s/reload_all.sh" % dir_path)
print("Applying to LED strip")
applyLed(red[0], green[0], blue[0])
print("All done :D")
if len(argv) < 4:
print("Usage: %s <Primary Color> <Secondary Color> <Background Color>" %
argv[0])
else:
main()