Created
October 20, 2023 19:19
-
-
Save chaorace/5b1ef9df454600defbe4947a80b6c601 to your computer and use it in GitHub Desktop.
Sync systemd/D-Bus environment variable updates w/ Emacs daemon
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Ensures that any change pushed to the systemd environment (e.g.: via dbus-update-activation-environment) immediately applies to the Emacs daemon process without needing to kill it first | |
;; This is useful for example if you run Emacs as a systemd user service and it happens to start before your WM, since this normally causes DISPLAY / WAYLAND_DISPLAY to be missing | |
;; Ensuring the variable is synced will fix issues like GUI apps not launching when invoked by emacs (e.g.: via xdg-open/shell mode) | |
;; Obviously, this code depends on D-Bus! | |
(dbus-register-monitor | |
:session | |
(lambda (&rest args) | |
(unless (null args) | |
(mapc | |
(lambda (var-expression) | |
(when (stringp var-expression) | |
(let ((splitted (split-string var-expression "="))) | |
(setenv (car splitted) (string-join (cdr splitted) "="))))) | |
(car args)))) | |
:path "/org/freedesktop/systemd1" | |
:interface "org.freedesktop.systemd1.Manager" | |
:member "SetEnvironment") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment