Skip to content

Instantly share code, notes, and snippets.

@htr
Last active December 15, 2015 22:59
Show Gist options
  • Save htr/5336800 to your computer and use it in GitHub Desktop.
Save htr/5336800 to your computer and use it in GitHub Desktop.
(define-minor-mode automate-mode
"Automate mode"
:group 'automate
:init-value t
:global nil
:lighter automate-lighter)
(defvar automate-lighter " auto")
(defvar automate:ongoing '())
(defun automate:reset-lighter ()
(setq automate-lighter (format " auto[%s]" (mapconcat 'identity automate:ongoing "|"))))
(defun automate:mk-sentinel (identifier)
(lambda (process event)
(message (process-name process))
(setq automate:ongoing (delq (process-name process) automate:ongoing))
(automate:reset-lighter)
(message (format "%s %s" (process-name process) event )))) ;; )
(defun automate:start-cmd (identifier cmd)
(let ((buffer-name (concat "cmd-" identifier)))
(progn
(when (get-buffer buffer-name)
(kill-buffer buffer-name))
(setq automate:ongoing (delete-dups (cons identifier automate:ongoing)))
(automate:reset-lighter)
(start-process-shell-command identifier (generate-new-buffer buffer-name) cmd)
(set-process-sentinel
(get-process identifier)
(automate:mk-sentinel identifier)))))
;; (define-minor-mode automate-mode "Automate mode" t "")
;; (automate:start-cmd "yada" "scp bigfile remoteserver: && ssh remoteserver ./deploy bigfile ")
(provide 'automate-mode)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment