-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspice
executable file
·118 lines (90 loc) · 3.19 KB
/
spice
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
#!/bin/python
from re import sub
from os.path import abspath, realpath, join, dirname
import os
from pathlib import Path
import glob
import argparse
#from current import background # Import current theme
colorama_init()
myhome = str(Path.home())
COLOURSCHEMEDIR = rf"{myhome}/.config/Spice/colourschemes/"
templatepath = rf"{myhome}/.config/Spice/templates/*"
templatedir = rf"{myhome}/.config/Spice/templates/"
def theme(args):
themename = "foo" #random code to fix stupid python indent errors :)
#args.theme[0]
parser = argparse.ArgumentParser(description = "Instantly theme your whole desktop", prog="spice")
opt = parser.add_argument_group("options")
# add argument
opt.add_argument("-l", "--list", action='store_true',
help = "List all available themes")
opt.add_argument("-p", "--path", metavar = "[themepath]", type = str, default = COLOURSCHEMEDIR,
help = "Path to folder containing custom theme file")
opt.add_argument("-t", "--theme", metavar = "[themename]", type = str, default = None)
opt.add_argument("-b", "--background", metavar = "[colour]", type = str, # default = "#ffff00",
help = 'Custom background HEX color e.g."ff0000"')
# parse the arguments from standard input
args = parser.parse_args()
# check if add argument has any input data.
# If it has, then print sum of the given numbers
if args.theme != None:
# theme(args)
COLOURSCHEMEDIR = args.path
themename = args.theme
os.system('rm $HOME/.config/Spice/current.py')
os.system('ln -s {}{}.bash $HOME/.config/Spice/current.py' .format(COLOURSCHEMEDIR, themename))
elif args.list != None:
os.system('ls $HOME/.config/Spice/colourschemes | cut -f1 -d"."')
raise SystemExit(1)
from current import * # Import current theme
if args.background != None:
background = args.background
else :
background = background
dict_replace = {
'{FOREGROUND}': foreground,
'{BACKGROUND}': background,
'{CURSOR}': cursor,
'{BLACK}': color0,
'{ALTBLACK}': color8,
'{RED}': color1,
'{ALTRED}': color9,
'{GREEN}': color2,
'{ALTGREEN}': color10,
'{YELLOW}': color3,
'{ALTYELLOW}': color11,
'{BLUE}': color4,
'{ALTBLUE}': color12,
'{MAGENTA}': color5,
'{ALTMAGENTA}': color13,
'{CYAN}': color6,
'{ALTCYAN}': color14,
'{WHITE}': color7,
'{ALTWHITE}': color15
}
for filepath in glob.iglob(templatepath):
#file = abspath(join(dirname(__file__), 'templates/foo.txt'))
file_open = open(filepath, 'r')
file_read = file_open.read()
file_open.close()
templatename1 = filepath.replace('\\', '/')
templatename2 = templatename1.replace(templatedir, '')
templatename = myhome + templatename2
new_file_open = open(templatename, 'w')
def replace_content(dict_replace, target):
"""Based on dict, replaces key with the value on the target."""
for check, replacer in list(dict_replace.items()):
target = sub(check, replacer, target)
# target = target.replace(check, replacer)
return target
new_content = replace_content(dict_replace, file_read)
new_file_open.write(new_content)
new_file_open.close()
# Test
print('Applying themes')
print('Reloading programs')
os.system(myhome+'/.config/Spice/reload.sh')
#print('Done!')
print('Set the {} theme.' .format(themename))
#os.system('neofetch')