I've written an interactive function which lets me shudown, reboot my machine as well as put it to sleep.
I'm using emacs and I'm just starting out getting into ELISP programming. As I'm a total beginner, I'd like to know what you would do differently in the following code to make it better, lighter and so on. Many thanks in advance.
(defun db/power-menu () "Interactive menu for shutdown, reboot or sleep." (interactive) (let ((actions '("Shutdown" "Reboot" "Sleep"))) (setq action (ivy-completing-read "What do you want to do?" actions )) (if (y-or-n-p (concat "Execute " action "? Unsaved progress will be lost. ")) (let ((default-directory "/sudo::")) (cond ((equal action "Shutdown") (shell-command "systemctl poweroff")) ((equal action "Reboot") (shell-command "systemctl reboot")) ((equal action "Sleep") (shell-command "systemctl suspend")))))))