2024-04-21 13:24:56 -07:00
|
|
|
#!/usr/bin/env python
|
2024-04-19 17:34:09 -07:00
|
|
|
import os
|
|
|
|
import toml
|
2024-04-19 17:57:08 -07:00
|
|
|
|
2024-04-19 17:34:09 -07:00
|
|
|
|
|
|
|
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):
|
2024-04-19 17:57:08 -07:00
|
|
|
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))
|
|
|
|
}
|
2024-04-19 17:34:09 -07:00
|
|
|
else:
|
|
|
|
drapeau_color_scheme_files = {}
|
|
|
|
|
|
|
|
# Extract colorscheme data from desired scheme
|
2024-04-19 17:57:08 -07:00
|
|
|
drapeau_color_scheme_dict = toml.load(
|
|
|
|
drapeau_color_scheme_files[drapeau_color_scheme]
|
|
|
|
)
|
2024-04-19 17:34:09 -07:00
|
|
|
|
|
|
|
# Add colorscheme to chezmoi config data
|
|
|
|
chezmoi_config_dict["data"]["drapeau"]["colors"] = drapeau_color_scheme_dict
|
|
|
|
|
|
|
|
# Write out modified dict to chezmoi config file
|
2024-04-19 17:57:08 -07:00
|
|
|
with open(chezmoi_config_file, "w") as f:
|
2024-04-19 17:34:09 -07:00
|
|
|
toml.dump(chezmoi_config_dict, f)
|
|
|
|
|
|
|
|
return "=== SUCCESS ==="
|
|
|
|
|
2024-04-19 17:57:08 -07:00
|
|
|
|
2024-04-19 17:34:09 -07:00
|
|
|
main()
|