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`.
This commit is contained in:
William Carroll 2021-03-23 11:23:42 -04:00
parent 2e1ccb7a90
commit b70dda5dcb

View file

@ -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."