diff options
Diffstat (limited to 'extras')
| -rwxr-xr-x | extras/HOME/.local/bin/rdectl | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/extras/HOME/.local/bin/rdectl b/extras/HOME/.local/bin/rdectl new file mode 100755 index 0000000..7c594f7 --- /dev/null +++ b/extras/HOME/.local/bin/rdectl @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 + +import os +import sys +import socket + + +def get_socket_path() -> str: + display = os.environ.get("DISPLAY") + if not display: + raise RuntimeError("DISPLAY is not set") + + display_suffix = display.replace(":", "", 1) + + runtime_dir = os.environ.get("XDG_RUNTIME_DIR") + base_dir = runtime_dir if runtime_dir else "/run/rde" + + return os.path.join(base_dir, f"rde-{display_suffix}.sock") + + +def main() -> int: + if len(sys.argv) < 2: + print(f"usage: {sys.argv[0]} <command...>", file=sys.stderr) + return 1 + + path = get_socket_path() + message = " ".join(sys.argv[1:]) + "\n" + + with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as sock: + sock.connect(path) + sock.sendall(message.encode("utf-8")) + + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) |