Created
August 25, 2022 19:30
-
-
Save tarneaux/5c90f78052bea625dbfdb84448bfd8ce to your computer and use it in GitHub Desktop.
Convert kitty theme to pywal theme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import os | |
import re | |
from sys import argv | |
def get_kitty_theme(): | |
with open(os.getenv('HOME') + '/.config/kitty/current-theme.conf', 'r') as f: | |
data = f.read() | |
return data | |
file = get_kitty_theme() | |
# Theme name example: "doom-one" instead of "Doom One" | |
theme_name = file.splitlines()[2].split(': ')[1].replace(' ', '-').lower() | |
# A string of the form "background: #000000" | |
color_pattern = re.compile(r'^[^ \#]* *#[^ \#]*$') | |
color_keys = [ | |
line.split(" ")[0] | |
for line in file.splitlines() | |
if color_pattern.match(line) | |
] | |
# Now we have all the keys, but we still need the values | |
color_values = [ | |
# Here we lowercase the values so that we don't have anything of the type #ECBE7B | |
# (we replace that with #ecbe7b, which is much better) | |
line.split(" ")[-1].lower() | |
for line in file.splitlines() | |
if color_pattern.match(line) | |
] | |
# Now we have a list of keys and values, we can make a dictionary | |
colors = dict(zip(color_keys, color_values)) | |
# We now make the dict that will go into the JSON file | |
json_dict = { | |
"wallpaper": argv[1], | |
"alpha": "100", | |
"special": { | |
"background": colors["background"], | |
"foreground": colors["foreground"], | |
"cursor": colors["cursor"] | |
}, | |
"colors": { | |
"color0": colors["color0"], | |
"color1": colors["color1"], | |
"color2": colors["color2"], | |
"color3": colors["color3"], | |
"color4": colors["color4"], | |
"color5": colors["color5"], | |
"color6": colors["color6"], | |
"color7": colors["color7"], | |
"color8": colors["color8"], | |
"color9": colors["color9"], | |
"color10": colors["color10"], | |
"color11": colors["color11"], | |
"color12": colors["color12"], | |
"color13": colors["color13"], | |
"color14": colors["color14"], | |
"color15": colors["color15"] | |
} | |
} | |
# We now make the JSON file | |
with open(os.getenv("HOME") + "/.cache/wal/schemes/" + theme_name + ".json", 'w') as f: | |
json.dump(json_dict, f) | |
# That's it! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment