about summary refs log tree commit diff
path: root/emacs
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2021-03-23T15·23-0400
committerWilliam Carroll <wpcarro@gmail.com>2021-03-23T15·32-0400
commitb70dda5dcb4310e8c1a28e0fee16a64c38987f29 (patch)
tree1123733433f5115c9ba8bbb0e00a0d2692b6dc39 /emacs
parent2e1ccb7a90d1857c30ae9d0b4d9de04150015020 (diff)
Refactor window-manager-logout
`sudo systemctl suspend` wasn't working because it required a secure password
prompt to read the user's password for `sudo`. The recommended way to call
`shell-command` with a `sudo` command (from what I read online) is to set
`default-directory` to `/sudo::` before calling `shell-command`. This works just
fine, so I refactored the function, `window-manager-logout`.
Diffstat (limited to 'emacs')
-rw-r--r--emacs/.emacs.d/wpc/window-manager.el36
1 files changed, 23 insertions, 13 deletions
diff --git a/emacs/.emacs.d/wpc/window-manager.el b/emacs/.emacs.d/wpc/window-manager.el
index f0dd196cc7fd..b69b77678f94 100644
--- a/emacs/.emacs.d/wpc/window-manager.el
+++ b/emacs/.emacs.d/wpc/window-manager.el
@@ -221,21 +221,31 @@ The following options are supported:
 
 Ivy is used to capture the user's input."
   (interactive)
-  (let* ((name->cmd `(("Lock" . ,window-manager--xsecurelock)
-                      ("Logout" . "sudo systemctl stop lightdm")
-                      ("Suspend" . ,(string-concat
-                                     window-manager--xsecurelock
-                                     " && systemctl suspend"))
-                      ("Hibernate" . ,(string-concat
-                                       window-manager--xsecurelock
-                                       " && systemctl hibernate"))
-                      ("Reboot" . "systemctl reboot")
-                      ("Shutdown" . "systemctl poweroff"))))
+  (let* ((name->cmd `(("Lock" .
+                       (lambda ()
+                         (shell-command window-manager--xsecurelock)))
+                      ("Logout" .
+                       (lambda ()
+                         (let ((default-directory "/sudo::"))
+                           (shell-command "systemctl stop lightdm"))))
+                      ("Suspend" .
+                       (lambda ()
+                         (shell-command "systemctl suspend")))
+                      ("Hibernate" .
+                       (lambda ()
+                         (shell-command "systemctl hibernate")))
+                      ("Reboot" .
+                       (lambda ()
+                         (let ((default-directory "/sudo::"))
+                           (shell-command "reboot"))))
+                      ("Shutdown" .
+                       (lambda ()
+                         (let ((default-directory "/sudo::"))
+                           (shell-command "shutdown now")))))))
     (funcall
      (lambda ()
-       (shell-command
-        (al-get (ivy-read "System: " (al-keys name->cmd))
-                name->cmd))))))
+       (funcall (al-get (ivy-read "System: " (al-keys name->cmd))
+                        name->cmd))))))
 
 (defun window-manager--label->index (label workspaces)
   "Return the index of the workspace in WORKSPACES named LABEL."