-
Notifications
You must be signed in to change notification settings - Fork 39
/
colors
executable file
·95 lines (78 loc) · 2.84 KB
/
colors
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
#!/usr/bin/python3
color_file = '/home/kristijan/.cache/main_colorscheme.conf'
colorschemes = {
'dark': 'tokyonight',
'light': 'onenord',
}
import pynvim
import argparse
import os
import sys
import time
from pathlib import Path
parser = argparse.ArgumentParser()
parser.add_argument('bg', nargs='?', default=None, choices=['dark', 'light', 'toggle'])
args = parser.parse_args()
bg = args.bg
current_bg = os.getenv('NVIM_COLORSCHEME_BG')
def set_env(background):
os.system('kitty @ set-colors --all --configured ' + color_file)
cmd = ['export NVIM_COLORSCHEME_BG=' + background]
cmd += ['export NVIM_COLORSCHEME=' + colorschemes[background]]
cmd += ['python ~/neovim-config/kitty/reload_colors.py']
return cmd
if Path(color_file).exists():
cfile = open(color_file, 'r')
first_line = cfile.readline().rstrip()
current_bg = first_line.split('=')[1]
elif not bg:
print('You must provide background type argument on first run', file=sys.stderr)
exit()
if not bg:
print(';'.join(set_env(current_bg)))
exit()
if bg == 'toggle':
bg = 'dark' if current_bg == 'light' else 'light'
os.environ['NVIM_COLORSCHEME_BG'] = bg
os.environ['NVIM_COLORSCHEME'] = colorschemes[bg]
nvim = pynvim.attach('child', argv=["/usr/bin/env", "nvim", "--embed", "--headless"])
def get_hl_color(name):
hl_output = nvim.call('execute', 'hi ' + name)
bgcolor = None
fgcolor = None
for item in hl_output.split('\n')[1].split():
if item.startswith('guifg'):
fgcolor = item.split('=')[1]
if item.startswith('guibg'):
bgcolor = item.split('=')[1]
return fgcolor or '', bgcolor or ''
normal_fg, normal_bg = get_hl_color('Normal')
cursor_fg, cursor_bg = get_hl_color('Cursor')
selection_fg, selection_bg = get_hl_color('Visual')
command = [
'env NVIM_COLORSCHEME_BG=' + bg,
'env NVIM_COLORSCHEME=' + colorschemes[bg],
'foreground ' + normal_fg,
'background ' + normal_bg,
'cursor ' + (cursor_bg.startswith('#') and cursor_bg or normal_fg),
'cursor_text_color background',
'selection_foreground ' + (selection_fg.startswith('#') and selection_fg or 'none'),
'selection_background ' + (selection_bg.startswith('#') and selection_bg or normal_fg)
]
for i in range(0, 16):
command.append('color' + str(i) + ' ' + nvim.eval('g:terminal_color_' + str(i)))
nvim.close()
file = open(color_file, 'w')
file.write('\n'.join(command))
file.close()
cmd = set_env(bg)
is_bg_changed = bg != current_bg
if is_bg_changed:
xresource_file = open('/home/kristijan/.Xresources_custom', 'w')
xresource_file.write('*polybar_bg: #FA' + normal_bg[1:] + '\n*polybar_fg:' + normal_fg)
xresource_file.close()
is_light = 'true' if bg == 'light' else 'false'
cmd += ['xrdb ~/.Xresources']
cmd += ['~/.config/polybar/start.sh']
cmd += ['source ~/.zshrc']
print(';'.join(cmd))