Skip to content

Instantly share code, notes, and snippets.

@Difrex
Last active August 1, 2018 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Difrex/5943fa332f187d8843c0bdfb14c5008f to your computer and use it in GitHub Desktop.
Save Difrex/5943fa332f187d8843c0bdfb14c5008f to your computer and use it in GitHub Desktop.

wal themes

solarized dark

{
  "special": {
    "background": "#002b36",
    "foreground": "#839496",
    "cursor": "#586e75"
  },
  "colors": {
    "color0": "#073642",
    "color1": "#dc322f",
    "color2": "#859900",
    "color3": "#b58900",
    "color4": "#268bd2",
    "color5": "#d33682",
    "color6": "#2aa198",
    "color7": "#eee8d5",
    "color8": "#6c7c80",
    "color9": "#dc322f",
    "color10": "#859900",
    "color11": "#b58900",
    "color12": "#268bd2",
    "color13": "#d33682",
    "color14": "#2aa198",
    "color15": "#eee8d5"
  }
}

Solarized light

{
  "special": {
    "background": "#fdf6e3",
    "foreground": "#657B83",
    "cursor": "#657b83"
  },
  "colors": {
    "color0": "#eee8d5",
    "color1": "#dc322f",
    "color2": "#859900",
    "color3": "#b58900",
    "color4": "#268bd2",
    "color5": "#d33682",
    "color6": "#2aa198",
    "color7": "#073642",
    "color8": "#6c7c80",
    "color9": "#dc322f",
    "color10": "#859900",
    "color11": "#b58900",
    "color12": "#268bd2",
    "color13": "#d33682",
    "color14": "#2aa198",
    "color15": "#073642"
  }
}

init.el

(defun set-light-theme()
        "Set solarized-light."
        (interactive)
        (load-theme 'solarized-light))
(defun set-dark-theme()
        "Set solarized-dark."
        (interactive)
        (load-theme 'solarized-dark))

theme_set.py

#!/usr/bin/python

import sys
from subprocess import Popen, PIPE


class Themer():

    def __init__(self, mode):
        self.mode = mode
        self.i3 = {
            "path": "/home/difrex/.config/i3/config",
            "dark": {
                "bar": [
                    "           # Solarized dark",
                    "           background #002b36",
                    "           statusline #839496",
                    "           separator  #586e75",
                    "           focused_workspace  #b58900 #b58900 #002b36",
                    "           active_workspace   #586e75 #586e75 #002b36",
                    "           inactive_workspace #073642 #002b36 #839496",
                    "           urgent_workspace   #dc322f #dc322f #fdf6e3"],
                "windows": """# Solarized dark
client.focused          #002b36 #586e75 #fdf6e3 #268bd2
client.focused_inactive #002b36 #073642 #839496 #073642
client.unfocused        #002b36 #073642 #839496 #073642
client.urgent           #002b36 #dc322f #fdf6e3 #002b36""",
                "terminal": "bindsym $mod+Return exec gnome-terminal --profile='Solarized Dark'",
            },
            "light": {
                "bar": [
                    "           # Solarized light",
                    "           separator #657b83",
                    "           background #fdf6e3",
                    "           statusline #073642",
                    "           focused_workspace  #fdf6e3 #fdf6e3 #268bd2",
                    "           active_workspace   #002b36 #fdf6e3 #002b36",
                    "           inactive_workspace #fdf6e3 #fdf6e3 #073642",
                    "           urgent_workspace   #f2777a #f2777a #ffffff"],
                "windows": """# Solarized light
client.focused         	#d33682 #d33682 #002b36 #d33682 #d33682
client.focused_inactive	#657b83 #002b36 #657b83 #268bd2 #268bd2
client.unfocused       	#657b83 #002b36 #657b83 #268bd2 #268bd2
client.urgent           #657b83 #002b36 #657b83 #268bd2 #268bd2""",
                "terminal": "bindsym $mod+Return exec gnome-terminal --profile='Solarized Light'"
            }
        }
        self.blocks = {
            "path": "/home/difrex/.config/i3blocks.conf",
            "dark": "command=~/.config/i3/blocks/battery2 dark",
            "light": "command=~/.config/i3/blocks/battery2 light"
        }
        self.dunst = {
            "path": "/home/difrex/.config/dunst/dunstrc",
            "dark": {
                "foreground": "#839496",
                "background": "#002b36",
                "frame": "#268bd2"
            },
            "light": {
                "foreground": "#073642",
                "background": "#fdf6e3",
                "frame": "#d33682"
            }
        }

    def replace(self, path, what, to):
        """Replace configuration with `what' to `to'"""
        f = open(path, "r")
        config = f.read()
        f.close()

        new_config = config.replace(what, to)

        fw = open(path, "w")
        fw.write(new_config)
        fw.close()

        if config == "\n".join(new_config):
            print("Something went wrong")

    def reload_i3(self):
        """Reload i3wm configuration"""
        reload_cmd = ["i3-msg", "restart"]
        p = Popen(reload_cmd, stdout=PIPE)
        stdout, stderr = p.communicate()
        print(stdout)

    def set_emacs_theme(self):
        """Set GNU Emacs theme"""
        cmd = ["emacsclient", "-e"]
        if self.mode == "dark":
            cmd.append("(set-dark-theme)")
        elif self.mode == "light":
            cmd.append("(set-light-theme)")
        p = Popen(cmd, stdout=PIPE)
        stdout, stderr = p.communicate()

    def reload_terminals(self):
        """Inject theme into running terminals"""
        if self.mode == "dark":
            cmd = ["wal", "-e", "-f", "solarized"]
        elif self.mode == "light":
            cmd = ["wal", "-e", "-l", "-f", "solarized"]
        p = Popen(cmd, stdout=PIPE)
        stdout, stderr = p.communicate()

    def restart_dunst(self):
        """Kill dunst"""
        cmd = ["killall", "dunst"]
        p = Popen(cmd, stdout=PIPE)
        stdout, stderr = p.communicate()

    def replace_i3_config(self):
        """Replace i3wm configuration"""
        if self.mode == "light":
            print("Change i3 dark theme to light")
            self.replace(self.i3["path"],
                         "\n".join(self.i3["dark"]["bar"]),
                         "\n".join(self.i3["light"]["bar"]))
            self.replace(self.i3["path"],
                         self.i3["dark"]["windows"],
                         self.i3["light"]["windows"])
            self.replace(self.i3["path"],
                         self.i3["dark"]["windows"],
                         self.i3["light"]["windows"])
            self.replace(self.i3["path"],
                         self.i3["dark"]["terminal"],
                         self.i3["light"]["terminal"])
        elif self.mode == "dark":
            print("Change i3 light theme to dark")
            self.replace(self.i3["path"],
                         "\n".join(self.i3["light"]["bar"]),
                         "\n".join(self.i3["dark"]["bar"]))
            self.replace(self.i3["path"],
                         self.i3["light"]["windows"],
                         self.i3["dark"]["windows"])
            self.replace(self.i3["path"],
                         self.i3["light"]["windows"],
                         self.i3["dark"]["windows"])
            self.replace(self.i3["path"],
                         self.i3["light"]["terminal"],
                         self.i3["dark"]["terminal"])
        else:
            self.exit()

    def replace_blocks_config(self):
        """Replace i3blocks configuration"""
        if self.mode == "light":
            print("Change i3blocks mode to light")
            self.replace(self.blocks["path"], self.blocks["dark"],
                         self.blocks["light"])
        elif self.mode == "dark":
            print("Change i3blocks mode to dark")
            self.replace(self.blocks["path"], self.blocks["light"],
                         self.blocks["dark"])
        else:
            self.exit()

    def replace_dunst_config(self):
        """Replace dunst configuration"""
        if self.mode == "light":
            print("Change dunst mode to light")
            for i in ["foreground", "background", "frame"]:
                self.replace(self.dunst["path"], self.dunst["dark"][i],
                             self.dunst["light"][i])
        elif self.mode == "dark":
            print("Change dunst mode to dark")
            for i in ["foreground", "background", "frame"]:
                self.replace(self.dunst["path"], self.dunst["light"][i],
                             self.dunst["dark"][i])
        else:
            self.exit()

    def change_theme(self):
        """Do config replace and reload"""

        # Change configuration
        self.replace_i3_config()
        self.replace_blocks_config()
        self.replace_dunst_config()

        # Apply
        self.reload_i3()
        self.restart_dunst()
        self.set_emacs_theme()
        self.reload_terminals()

    @staticmethod
    def exit():
        print("Wrong mode")
        sys.exit(2)


if __name__ == "__main__":
    if len(sys.argv) < 2:
        print("USAGE: " + sys.argv[0] + " <mode>")
        sys.exit(2)

    mode = sys.argv[1]
    config = Themer(mode)
    config.change_theme()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment