#!/usr/bin/env python3 # A script to update the colors in specific config files for easy ricing. # By David Penkowoj, 2022-03-18 import os # Get colors and loop over relevant configs def replace_color_configs(): with open("/home/me/.cache/wal/oldcolors") as old_color_file: old_colors = [ color.replace("\n", "") for color in old_color_file.readlines() ] with open("/home/me/.cache/wal/colors") as new_color_file: new_colors = [ color.replace("\n", "") for color in new_color_file.readlines() ] for config in relevant: find_and_replace_config(config, old_colors, new_colors) def find_and_replace_config(file_path, old_colors, new_colors): with open(file_path, "r") as file: data = file.read() for color in old_colors: if data.find(color) != -1: index = old_colors.index(color) data = data.replace(color, new_colors[index]) with open(file_path, "w") as file: file.write(data) relevant = [ "/home/me/.config/dunst/dunstrc", "/home/me/.config/zathura/zathurarc", "/home/me/.config/flameshot/flameshot.ini", "/home/me/.config/qutebrowser/utils.py", ] if __name__ == "__main__": os.system('xrdb -merge "$HOME/.cache/wal/colors.Xresources"') os.system('xrdb -merge "$HOME/.Xresources"') replace_color_configs() os.system('killall dunst')