diff options
author | Óscar Nájera <hi@oscarnajera.com> | 2022-08-28 19:59:20 +0200 |
---|---|---|
committer | Óscar Nájera <hi@oscarnajera.com> | 2022-08-28 19:59:20 +0200 |
commit | 1ce1552763ceae4219e4f99bcbb8df3d29c55ef8 (patch) | |
tree | cdfcedc42eded21aba5189a7f0ebde35aac6b6c8 | |
parent | 426890768c315fc8ba350d936feab325e755c430 (diff) | |
download | dotfiles-1ce1552763ceae4219e4f99bcbb8df3d29c55ef8.tar.gz dotfiles-1ce1552763ceae4219e4f99bcbb8df3d29c55ef8.tar.bz2 dotfiles-1ce1552763ceae4219e4f99bcbb8df3d29c55ef8.zip |
shepherd manager ensure service is set
-rw-r--r-- | elisp/shepherd.el | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/elisp/shepherd.el b/elisp/shepherd.el index 6cf2e1b..22acbb1 100644 --- a/elisp/shepherd.el +++ b/elisp/shepherd.el @@ -20,14 +20,13 @@ ;;; Code: (require 'subr-x) -(require 'dash) (require 'helm) (defun shepherd-command (&rest cmds) "Call herd with CMDS." - (with-output-to-string - (with-current-buffer standard-output - (apply #'call-process "herd" nil t nil cmds)))) + (with-temp-buffer + (apply #'call-process "herd" nil t nil cmds) + (string-trim (buffer-string)))) (defun shepherd-services () "List all enabled shepherd services." @@ -37,12 +36,17 @@ (let (matches) (while (search-forward-regexp (rx (group (or "+" "-")) space (group (+ any))) nil t) (let ((status (if (string= (match-string 1) "+") - (propertize "started" 'face 'font-lock-function-name-face) - (propertize "stopped" 'face 'font-lock-variable-name-face))) + (propertize "start" 'face 'font-lock-function-name-face) + (propertize "stop" 'face 'font-lock-variable-name-face))) (service (match-string 2))) (push (cons service status) matches))) (sort matches (lambda (a b) (string< (car a) (car b))))))) +(defun shepherd-set (service status) + "Ensure SERVICE is in STATUS." + (unless (string= status (cdr (assoc service (shepherd-services)))) + (shepherd-command (symbol-name status) service))) + (defun shepherd () "Manage shepherd services." (interactive) @@ -50,17 +54,15 @@ :prompt "Shepherd service:" :sources (helm-build-sync-source "Services" :candidates - (--map (cons (format "%s\t%s" (car it) (cdr it)) - (car it)) - (shepherd-services)) + (cl-loop for it in (shepherd-services) + collect (cons (format "%s\t%s" (cdr it) (car it)) + (car it))) :action (mapcar (lambda (action) (let ((name (symbol-name action))) `(,name . (lambda (service) - (message - (string-trim - (shepherd-command ,name service))))))) + (message (shepherd-command ,name service)))))) '(status start stop restart))))) (provide 'shepherd) |