Add some utility functions to the shell module to be used in the project interface
This commit is contained in:
parent
5cd3bde92c
commit
1d45057dda
|
@ -54,6 +54,8 @@
|
|||
(require 'cubes/agda)
|
||||
(require 'cubes/notifications)
|
||||
(require 'cubes/noether)
|
||||
(require 'cubes/nix)
|
||||
(require 'cubes/julia)
|
||||
|
||||
|
||||
(defcube fg42/editor
|
||||
|
|
|
@ -97,7 +97,7 @@ It's mapping of project name to the project datastructure")
|
|||
(format "Run the slot number %s of the current project." ,x)
|
||||
(interactive)
|
||||
(fg42/project-run-slot ,x))
|
||||
(define-key fg42-project-global-mode-map (kbd ,(format "s-s %s" x))
|
||||
(define-key fg42-project-global-mode-map (kbd ,(format "C-c C-%s" x))
|
||||
(function ,(intern (format "fg42/project-slot-%s" x))))))
|
||||
(number-sequence 0 n))))
|
||||
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
(require 'seq)
|
||||
(require 'fg42/utils)
|
||||
|
||||
(fpkg/require 's)
|
||||
|
||||
(defmacro ->commands (&rest body)
|
||||
"Return a list of shell commands in the BODY.
|
||||
|
||||
|
@ -37,9 +39,15 @@ the arguments get evaluated."
|
|||
(lambda (x)
|
||||
(when (not (listp x))
|
||||
(error "Expect a list. Got %s" x))
|
||||
(format "%s %s" (car x) (mapconcat #'eval (cdr x) " ")))
|
||||
(let ((command (car x))
|
||||
(args (cdr x)))
|
||||
(cond
|
||||
((string= command "and") (s-join " && " (eval `(->commands ,@args))))
|
||||
((string= command "or") (s-join " || " (eval `(->commands ,@args))))
|
||||
(t (format "%s %s" command (mapconcat #'eval args " "))))))
|
||||
body)))
|
||||
|
||||
|
||||
(defun shell<- (commands &rest opts)
|
||||
"Run the give list of COMMANDS via ssh on HOST with the given OPTS.
|
||||
|
||||
|
@ -78,11 +86,11 @@ OPTS:
|
|||
- `:shell' The shell to run the commands with. (default /bin/bash)
|
||||
- `:buffer' The buffer name to use. (default '*ssh[HOST]*')
|
||||
- `:erase?' Whether or not erase the buffer. (default t)"
|
||||
(let ((sh (or (plist-get opts :shell) "/bin/bash"))
|
||||
(buffer (or (plist-get opts :buffer) (format "*ssh[%s]*" host)))
|
||||
(erase? (or (plist-get opts :erase-buffer?) t))
|
||||
(cmds (format "'%s'" (mapconcat #'identity commands ";")))
|
||||
(output-buffer (get-buffer-create buffer)))
|
||||
(let* ((sh (or (plist-get opts :shell) "/bin/bash"))
|
||||
(buffer (or (plist-get opts :buffer) (format "*ssh[%s]*" host)))
|
||||
(erase? (or (plist-get opts :erase-buffer?) t))
|
||||
(cmds (format "'%s'" (mapconcat #'identity commands ";")))
|
||||
(output-buffer (get-buffer-create buffer)))
|
||||
|
||||
(when erase?
|
||||
(with-current-buffer output-buffer
|
||||
|
@ -101,9 +109,8 @@ OPTS:
|
|||
(when (string= event "finished\n")
|
||||
(message "Commands finished. Closing SSH connection.")
|
||||
;;(kill-process process)
|
||||
))))
|
||||
(message "Task started on %s -> %s" host (buffer-name output-buffer))))
|
||||
))))))
|
||||
|
||||
|
||||
(provide 'fg42/ssh)
|
||||
(provide 'fg42/shell)
|
||||
;;; ssh.el ends here
|
||||
|
|
Loading…
Reference in New Issue