aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--elisp/shepherd.el26
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)