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." Ivy is used to capture the user's input."
(interactive) (interactive)
(let* ((name->cmd `(("Lock" . ,window-manager--xsecurelock) (let* ((name->cmd `(("Lock" .
("Logout" . "sudo systemctl stop lightdm") (lambda ()
("Suspend" . ,(string-concat (shell-command window-manager--xsecurelock)))
window-manager--xsecurelock ("Logout" .
" && systemctl suspend")) (lambda ()
("Hibernate" . ,(string-concat (let ((default-directory "/sudo::"))
window-manager--xsecurelock (shell-command "systemctl stop lightdm"))))
" && systemctl hibernate")) ("Suspend" .
("Reboot" . "systemctl reboot") (lambda ()
("Shutdown" . "systemctl poweroff")))) (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 (funcall
(lambda () (lambda ()
(shell-command (funcall (al-get (ivy-read "System: " (al-keys name->cmd))
(al-get (ivy-read "System: " (al-keys name->cmd)) name->cmd))))))
name->cmd))))))
(defun window-manager--label->index (label workspaces) (defun window-manager--label->index (label workspaces)
"Return the index of the workspace in WORKSPACES named LABEL." "Return the index of the workspace in WORKSPACES named LABEL."