reload: Check pids first.

This commit is contained in:
Dylan Araps 2018-07-06 09:04:49 +10:00
parent 7e797405c5
commit f26a8bbb5e
2 changed files with 12 additions and 4 deletions

View File

@ -61,25 +61,25 @@ def gtk():
def i3():
"""Reload i3 colors."""
if shutil.which("i3-msg"):
if shutil.which("i3-msg") and util.get_pid("i3"):
util.disown(["i3-msg", "reload"])
def kitty():
""" Reload kitty colors. """
if shutil.which("kitty"):
if shutil.which("kitty") and util.get_pid("kitty"):
util.disown(["kitty", "@", "set-colors", "--all"])
def polybar():
"""Reload polybar colors."""
if shutil.which("polybar"):
if shutil.which("polybar") and util.get_pid("polybar"):
util.disown(["pkill", "-USR1", "polybar"])
def sway():
"""Reload sway colors."""
if shutil.which("swaymsg"):
if shutil.which("swaymsg") and util.get_pid("sway"):
util.disown(["swaymsg", "reload"])

View File

@ -168,3 +168,11 @@ def disown(cmd):
subprocess.Popen(cmd,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL)
def get_pid(name):
"""Check if process is running by name."""
try:
subprocess.check_output(["pidof", "-s", name])
except subprocess.CalledProcessError:
return False