#!/usr/bin/env python3 # A script to update the colors in specific config files for easy ricing. # Depenencies: # 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: 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) # Change config for zathura def change_zathura(old_colors, new_colors): file_path = "/home/me/.config/zathura/zathurarc" find_and_replace_config(file_path, old_colors, new_colors) def change_qutebrowser(old_colors, new_colors): file_path = "/home/me/.config/qutebrowser/utils.py" find_and_replace_config(file_path, old_colors, new_colors) # change_nvim # change_dunst, relevant = [ change_zathura, change_qutebrowser, ] if __name__ == "__main__": os.system('xrdb -merge "$HOME/.cache/wal/colors.Xresources"') os.system('xrdb -merge "$HOME/.Xresources"') replace_color_configs()