Add color switching

This commit is contained in:
Fabian Ising
2022-10-24 11:38:50 +02:00
parent 0b2f96683c
commit 982dd1d1bf
7 changed files with 1589 additions and 29 deletions

1
.config/alacritty/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
schemes.yml

View File

@@ -1,3 +1,6 @@
import:
- ~/.config/alacritty/schemes.yml
env:
TERM: xterm-256color
font:
@@ -26,36 +29,11 @@ window:
scrolling:
history: 0
colors:
# Default colors
primary:
background: '0x323232'
foreground: '0xeeeeec'
# Normal colors
normal:
black: '0x2e3436'
red: '0xcc0000'
green: '0x4e9a06'
yellow: '0xc4a000'
blue: '0x3465a4'
magenta: '0x75507b'
cyan: '0x06989a'
white: '0xd3d7cf'
# Bright colors
bright:
black: '0x555753'
red: '0xef2929'
green: '0x8ae234'
yellow: '0xfce94f'
blue: '0x729fcf'
magenta: '0xad7fa8'
cyan: '0x34e2e2'
white: '0xeeeeec'
shell:
program: tmux
alt_send_esc: false
live_config_reload: true
key_bindings:
- { key: F, mods: Control, command: {program: "zsh", args: ["-c","PATH=/usr/local/bin:$PATH python3 ~/.config/alacritty/color_switcher.py 2>&1 >> /tmp/ala.log"]} }

View File

@@ -0,0 +1,66 @@
#!/usr/bin/env python3
import os
import re
CONFIG_FILE_NAME = "schemes.yml"
CONFIG_FILE_DIR = os.path.expanduser("~/.config/alacritty/")
CONFIG_FILE_PATH = os.path.join(CONFIG_FILE_DIR, CONFIG_FILE_NAME)
COLOR_SCHEME_LINE_SEARCH = "colors: \*(\S+)"
COLOR_SCHEME_LINE_TEMPLATE = "colors: *{}\n"
NVIM_CONFIG_FILE_DIR = os.path.expanduser("~/.config/nvim/")
NVIM_CONFIG_FILE_NAME = "scheme.vim"
NVIM_CONFIG_FILE_PATH = os.path.join(NVIM_CONFIG_FILE_DIR, NVIM_CONFIG_FILE_NAME)
NVIM_COLOR_SCHEME_LINE_SEARCH = "set background=(\S+)\ncolorscheme (\S+)"
NVIM_COLOR_SCHEME_LINE_TEMPLATE = "set background={}\ncolorscheme {}"
def change_alacritty_theme():
with open(CONFIG_FILE_PATH, "r") as config_file:
config_file.seek(0)
lines = config_file.readlines()
colors_line_index = -1
for i, line in enumerate(lines):
match = re.search(COLOR_SCHEME_LINE_SEARCH, line)
if match is not None:
current_color_scheme = match.group(1)
colors_line_index = i
if current_color_scheme == "dark_mode":
new_scheme = "solarized_light"
else:
new_scheme = "dark_mode"
lines[colors_line_index] = COLOR_SCHEME_LINE_TEMPLATE.format(
new_scheme)
with open(CONFIG_FILE_PATH, "w") as config_file:
for line in lines:
config_file.write(line)
return new_scheme
def change_vim_theme(light_mode=False):
with open(NVIM_CONFIG_FILE_PATH, "r") as config_file:
config_file.seek(0)
config = config_file.read()
if light_mode:
color_line = NVIM_COLOR_SCHEME_LINE_TEMPLATE.format("light", "solarized")
else:
color_line = NVIM_COLOR_SCHEME_LINE_TEMPLATE.format("dark", "badwolf")
res = re.sub(NVIM_COLOR_SCHEME_LINE_SEARCH, color_line, config)
with open(NVIM_CONFIG_FILE_PATH, "w") as config_file:
config = config_file.write(res)
def main():
new_theme = change_alacritty_theme()
change_vim_theme(new_theme == "solarized_light")
if __name__=="__main__":
main()

File diff suppressed because it is too large Load Diff

3
nvim/.gitignore vendored
View File

@@ -6,3 +6,6 @@ __pycache__/
bundle/*
!bundle/Vundle.vim
*.swp
# Prevent changes to propagate to all systems
scheme.vim

View File

@@ -85,7 +85,11 @@ set t_Co=256
"set term=screen-256color
" Color configuration
colorscheme badwolf " some color ..
try
source ~/.config/nvim/scheme.vim
catch
" Ignore non existing file
endtry
syntax enable " enable syntax processing
" Disable annoying bell

2
nvim/scheme.vim Normal file
View File

@@ -0,0 +1,2 @@
set background=dark
colorscheme badwolf