efficient vim config
[dotfiles/.git] / .local / lib / python3.9 / site-packages / pywal / reload.py
1 """
2 Reload programs.
3 """
4 import logging
5 import os
6 import shutil
7 import subprocess
8
9 from .settings import CACHE_DIR, MODULE_DIR, OS
10 from . import util
11
12
13 def tty(tty_reload):
14     """Load colors in tty."""
15     tty_script = os.path.join(CACHE_DIR, "colors-tty.sh")
16     term = os.environ.get("TERM")
17
18     if tty_reload and term == "linux":
19         subprocess.Popen(["sh", tty_script])
20
21
22 def xrdb(xrdb_files=None):
23     """Merge the colors into the X db so new terminals use them."""
24     xrdb_files = xrdb_files or \
25         [os.path.join(CACHE_DIR, "colors.Xresources")]
26
27     if shutil.which("xrdb") and OS != "Darwin":
28         for file in xrdb_files:
29             subprocess.run(["xrdb", "-merge", "-quiet", file])
30
31
32 def gtk():
33     """Reload GTK theme on the fly."""
34     # Here we call a Python 2 script to reload the GTK themes.
35     # This is done because the Python 3 GTK/Gdk libraries don't
36     # provide a way of doing this.
37     if shutil.which("python2"):
38         gtk_reload = os.path.join(MODULE_DIR, "scripts", "gtk_reload.py")
39         util.disown(["python2", gtk_reload])
40
41     else:
42         logging.warning("GTK2 reload support requires Python 2.")
43
44
45 def i3():
46     """Reload i3 colors."""
47     if shutil.which("i3-msg") and util.get_pid("i3"):
48         util.disown(["i3-msg", "reload"])
49
50
51 def kitty():
52     """ Reload kitty colors. """
53     if shutil.which("kitty") and util.get_pid("kitty"):
54         util.disown(["kitty", "@", "set-colors", "--all"])
55
56
57 def polybar():
58     """Reload polybar colors."""
59     if shutil.which("polybar") and util.get_pid("polybar"):
60         util.disown(["pkill", "-USR1", "polybar"])
61
62
63 def sway():
64     """Reload sway colors."""
65     if shutil.which("swaymsg") and util.get_pid("sway"):
66         util.disown(["swaymsg", "reload"])
67
68
69 def colors(cache_dir=CACHE_DIR):
70     """Reload colors. (Deprecated)"""
71     sequences = os.path.join(cache_dir, "sequences")
72
73     logging.error("'wal -r' is deprecated: "
74                   "Use 'cat %s' instead.", sequences)
75
76     if os.path.isfile(sequences):
77         print("".join(util.read_file(sequences)), end="")
78
79
80 def env(xrdb_file=None, tty_reload=True):
81     """Reload environment."""
82     xrdb(xrdb_file)
83     i3()
84     kitty()
85     sway()
86     polybar()
87     logging.info("Reloaded environment.")
88     tty(tty_reload)