diff --git a/.chezmoiscripts/run_drapeau.py b/.chezmoiscripts/run_drapeau.py new file mode 100644 index 0000000..1f3efa5 --- /dev/null +++ b/.chezmoiscripts/run_drapeau.py @@ -0,0 +1,47 @@ +#!/usr/bin/python +import os +import toml + +def main(): + # Chech if config file exists + chezmoi_config_dir = os.path.join(os.environ["HOME"], ".config", "chezmoi") + if os.path.exists(os.path.join(chezmoi_config_dir, "chezmoi.toml")): + chezmoi_config_file = os.path.join(chezmoi_config_dir, "chezmoi.toml") + else: + return "=== ERROR: No chezmoi.toml found ===" + + # Load config file into memory + chezmoi_config_dict = toml.load(chezmoi_config_file) + + # Extract drapeau data + if "drapeau" not in chezmoi_config_dict["data"]: + chezmoi_config_dict["data"]["drapeau"] = {} + + # Get colorscheme + if "colorscheme" in chezmoi_config_dict["data"]["drapeau"]: + drapeau_color_scheme = chezmoi_config_dict["data"]["drapeau"]["colorscheme"] + else: + drapeau_color_scheme = "default" + chezmoi_config_dict["data"]["drapeau"]["colorscheme"] = drapeau_color_scheme + + # Find colorscheme files + # Produce dict of {"name": "path"} for all schemes + drapeau_config_dir = os.path.join(os.environ["HOME"], ".config", "drapeau") + if os.path.exists(drapeau_config_dir): + drapeau_color_scheme_files = {".".join(scheme.split(".")[:-1]): os.path.join(drapeau_config_dir, scheme) for scheme in os.listdir(drapeau_config_dir) if os.path.isfile(os.path.join(drapeau_config_dir, scheme))} + else: + drapeau_color_scheme_files = {} + + # Extract colorscheme data from desired scheme + drapeau_color_scheme_dict = toml.load(drapeau_color_scheme_files[drapeau_color_scheme]) + + # Add colorscheme to chezmoi config data + chezmoi_config_dict["data"]["drapeau"]["colors"] = drapeau_color_scheme_dict + + # Write out modified dict to chezmoi config file + with open(chezmoi_config_file, 'w') as f: + toml.dump(chezmoi_config_dict, f) + + return "=== SUCCESS ===" + +main() diff --git a/.chezmoidata/catppuccin-frappe.toml b/dot_config/drapeau/catppuccin-frappe.toml similarity index 100% rename from .chezmoidata/catppuccin-frappe.toml rename to dot_config/drapeau/catppuccin-frappe.toml diff --git a/.chezmoidata/catppuccin-latte.toml b/dot_config/drapeau/catppuccin-latte.toml similarity index 100% rename from .chezmoidata/catppuccin-latte.toml rename to dot_config/drapeau/catppuccin-latte.toml diff --git a/.chezmoidata/catppuccin-macchato.toml b/dot_config/drapeau/catppuccin-macchato.toml similarity index 100% rename from .chezmoidata/catppuccin-macchato.toml rename to dot_config/drapeau/catppuccin-macchato.toml diff --git a/.chezmoidata/catppuccin-mocha.toml b/dot_config/drapeau/catppuccin-mocha.toml similarity index 100% rename from .chezmoidata/catppuccin-mocha.toml rename to dot_config/drapeau/catppuccin-mocha.toml