From 4cb5174b1d1d37818a1a3a6630badb346298a0d1 Mon Sep 17 00:00:00 2001 From: Sho Date: Sat, 1 Aug 2026 21:19:39 +0900 Subject: [PATCH] fix(fastfetch): make fastfetch theme sync non-destructive to preserve layout and modules --- quickshell/services/python/theme_sync.py | 27 +++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/quickshell/services/python/theme_sync.py b/quickshell/services/python/theme_sync.py index 25f682c..3787f86 100644 --- a/quickshell/services/python/theme_sync.py +++ b/quickshell/services/python/theme_sync.py @@ -1006,10 +1006,35 @@ theme[upload_end]="#ff80bf" pass def sync_fastfetch(bg, surface, current_line, fg, accent, sub_accent): + import re fastfetch_dir = os.path.expanduser('~/.config/fastfetch') os.makedirs(fastfetch_dir, exist_ok=True) conf_path = os.path.join(fastfetch_dir, 'config.jsonc') + if os.path.exists(conf_path): + try: + with open(conf_path, 'r', encoding='utf-8') as f: + content = f.read() + + modified = False + if '"keys"' in content: + content, count1 = re.subn(r'"keys"\s*:\s*"[^"]*"', f'"keys": "{accent}"', content) + if count1 > 0: modified = True + if '"title"' in content: + content, count2 = re.subn(r'"title"\s*:\s*"[^"]*"', f'"title": "{sub_accent}"', content) + if count2 > 0: modified = True + + if not modified and '"display"' in content: + content = re.sub(r'"display"\s*:\s*\{', f'"display": {{\n "color": {{\n "keys": "{accent}",\n "title": "{sub_accent}"\n }},', content, count=1) + modified = True + + if modified: + with open(conf_path, 'w', encoding='utf-8') as f: + f.write(content) + return + except Exception: + pass + fastfetch_jsonc = f"""{{ "$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json", "display": {{ @@ -1039,7 +1064,7 @@ def sync_fastfetch(bg, surface, current_line, fg, accent, sub_accent): }} """ try: - with open(conf_path, 'w') as f: + with open(conf_path, 'w', encoding='utf-8') as f: f.write(fastfetch_jsonc) except Exception: pass