Add color switching
This commit is contained in:
1
.config/alacritty/.gitignore
vendored
Normal file
1
.config/alacritty/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
schemes.yml
|
||||||
@@ -1,3 +1,6 @@
|
|||||||
|
import:
|
||||||
|
- ~/.config/alacritty/schemes.yml
|
||||||
|
|
||||||
env:
|
env:
|
||||||
TERM: xterm-256color
|
TERM: xterm-256color
|
||||||
font:
|
font:
|
||||||
@@ -26,36 +29,11 @@ window:
|
|||||||
scrolling:
|
scrolling:
|
||||||
history: 0
|
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:
|
shell:
|
||||||
program: tmux
|
program: tmux
|
||||||
|
|
||||||
alt_send_esc: false
|
alt_send_esc: false
|
||||||
live_config_reload: true
|
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"]} }
|
||||||
|
|||||||
66
.config/alacritty/color_switcher.py
Executable file
66
.config/alacritty/color_switcher.py
Executable 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()
|
||||||
1506
.config/alacritty/schemes.yml
Normal file
1506
.config/alacritty/schemes.yml
Normal file
File diff suppressed because it is too large
Load Diff
3
nvim/.gitignore
vendored
3
nvim/.gitignore
vendored
@@ -6,3 +6,6 @@ __pycache__/
|
|||||||
bundle/*
|
bundle/*
|
||||||
!bundle/Vundle.vim
|
!bundle/Vundle.vim
|
||||||
*.swp
|
*.swp
|
||||||
|
|
||||||
|
# Prevent changes to propagate to all systems
|
||||||
|
scheme.vim
|
||||||
|
|||||||
@@ -85,7 +85,11 @@ set t_Co=256
|
|||||||
"set term=screen-256color
|
"set term=screen-256color
|
||||||
|
|
||||||
" Color configuration
|
" Color configuration
|
||||||
colorscheme badwolf " some color ..
|
try
|
||||||
|
source ~/.config/nvim/scheme.vim
|
||||||
|
catch
|
||||||
|
" Ignore non existing file
|
||||||
|
endtry
|
||||||
syntax enable " enable syntax processing
|
syntax enable " enable syntax processing
|
||||||
|
|
||||||
" Disable annoying bell
|
" Disable annoying bell
|
||||||
|
|||||||
2
nvim/scheme.vim
Normal file
2
nvim/scheme.vim
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
set background=dark
|
||||||
|
colorscheme badwolf
|
||||||
Reference in New Issue
Block a user