aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorÓscar Nájera <hi@oscarnajera.com>2022-04-20 16:19:29 +0200
committerÓscar Nájera <hi@oscarnajera.com>2022-04-20 16:19:29 +0200
commit8cb58cc43cd329fbae75cedd1e889d977f0f9226 (patch)
tree2a24fbf70e7161b8308a338987afee9d0ea2329a
parentb48072aca0edf714cb0386ce4a82eb13c274e960 (diff)
downloaddotfiles-8cb58cc43cd329fbae75cedd1e889d977f0f9226.tar.gz
dotfiles-8cb58cc43cd329fbae75cedd1e889d977f0f9226.tar.bz2
dotfiles-8cb58cc43cd329fbae75cedd1e889d977f0f9226.zip
manage shepherd services
-rw-r--r--config/doom/config.org5
-rw-r--r--elisp/shepherd.el67
2 files changed, 72 insertions, 0 deletions
diff --git a/config/doom/config.org b/config/doom/config.org
index 4a057db..b926dfa 100644
--- a/config/doom/config.org
+++ b/config/doom/config.org
@@ -456,3 +456,8 @@ Emacs mode for managing ledger text files
#+begin_src emacs-lisp
(use-package! json-rpc)
#+end_src
+#+begin_src emacs-lisp
+(use-package! shepherd
+ :load-path "~/dev/dotfiles/elisp/"
+ :commands (shepherd))
+#+end_src
diff --git a/elisp/shepherd.el b/elisp/shepherd.el
new file mode 100644
index 0000000..4ba5ed0
--- /dev/null
+++ b/elisp/shepherd.el
@@ -0,0 +1,67 @@
+;;; shepherd.el --- Manage shepherd services -*- lexical-binding: t; -*-
+;;
+;; Copyright (C) 2022 Óscar Nájera
+;;
+;; Author: Óscar Nájera <hi@oscarnajera.com>
+;; Maintainer: Óscar Nájera <hi@oscarnajera.com>
+;; Created: April 20, 2022
+;; Modified: April 20, 2022
+;; Version: 0.0.1
+;; Keywords: abbrev bib c calendar comm convenience data docs emulations extensions faces files frames games hardware help hypermedia i18n internal languages lisp local maint mail matching mouse multimedia news outlines processes terminals tex tools unix vc wp
+;; Homepage: https://github.com/titan/shepherd
+;; Package-Requires: ((emacs "25.1"))
+;;
+;; This file is not part of GNU Emacs.
+;;
+;;; Commentary:
+;;
+;; Manage shepherd services
+;;
+;;; 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))))
+
+(defun shepherd-services ()
+ "List all enabled shepherd services."
+ (with-temp-buffer
+ (insert (shepherd-command "status"))
+ (goto-char (point-min))
+ (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)))
+ (service (match-string 2)))
+ (push (cons service status) matches)))
+ (sort matches (lambda (a b) (string< (car a) (car b)))))))
+
+(defun shepherd ()
+ "Manage shepherd services."
+ (interactive)
+ (helm
+ :prompt "Shepherd service:"
+ :sources (helm-build-sync-source "Services"
+ :candidates
+ (--map (cons (format "%s\t%s" (car it) (cdr it))
+ (car it))
+ (shepherd-services))
+ :action
+ (mapcar (lambda (action)
+ (let ((name (symbol-name action)))
+ `(,name .
+ (lambda (service)
+ (message
+ (string-trim
+ (shepherd-command ,name service)))))))
+ '(status start stop)))))
+
+(provide 'shepherd)
+;;; shepherd.el ends here