diff options
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 |
commit | 8cb58cc43cd329fbae75cedd1e889d977f0f9226 (patch) | |
tree | 2a24fbf70e7161b8308a338987afee9d0ea2329a /elisp | |
parent | b48072aca0edf714cb0386ce4a82eb13c274e960 (diff) | |
download | dotfiles-8cb58cc43cd329fbae75cedd1e889d977f0f9226.tar.gz dotfiles-8cb58cc43cd329fbae75cedd1e889d977f0f9226.tar.bz2 dotfiles-8cb58cc43cd329fbae75cedd1e889d977f0f9226.zip |
manage shepherd services
Diffstat (limited to 'elisp')
-rw-r--r-- | elisp/shepherd.el | 67 |
1 files changed, 67 insertions, 0 deletions
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 |