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/agda)
|
||||||
(require 'cubes/notifications)
|
(require 'cubes/notifications)
|
||||||
(require 'cubes/noether)
|
(require 'cubes/noether)
|
||||||
|
(require 'cubes/nix)
|
||||||
|
(require 'cubes/julia)
|
||||||
|
|
||||||
|
|
||||||
(defcube fg42/editor
|
(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)
|
(format "Run the slot number %s of the current project." ,x)
|
||||||
(interactive)
|
(interactive)
|
||||||
(fg42/project-run-slot ,x))
|
(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))))))
|
(function ,(intern (format "fg42/project-slot-%s" x))))))
|
||||||
(number-sequence 0 n))))
|
(number-sequence 0 n))))
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,8 @@
|
||||||
(require 'seq)
|
(require 'seq)
|
||||||
(require 'fg42/utils)
|
(require 'fg42/utils)
|
||||||
|
|
||||||
|
(fpkg/require 's)
|
||||||
|
|
||||||
(defmacro ->commands (&rest body)
|
(defmacro ->commands (&rest body)
|
||||||
"Return a list of shell commands in the BODY.
|
"Return a list of shell commands in the BODY.
|
||||||
|
|
||||||
|
@ -37,9 +39,15 @@ the arguments get evaluated."
|
||||||
(lambda (x)
|
(lambda (x)
|
||||||
(when (not (listp x))
|
(when (not (listp x))
|
||||||
(error "Expect a list. Got %s" 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)))
|
body)))
|
||||||
|
|
||||||
|
|
||||||
(defun shell<- (commands &rest opts)
|
(defun shell<- (commands &rest opts)
|
||||||
"Run the give list of COMMANDS via ssh on HOST with the given 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)
|
- `:shell' The shell to run the commands with. (default /bin/bash)
|
||||||
- `:buffer' The buffer name to use. (default '*ssh[HOST]*')
|
- `:buffer' The buffer name to use. (default '*ssh[HOST]*')
|
||||||
- `:erase?' Whether or not erase the buffer. (default t)"
|
- `:erase?' Whether or not erase the buffer. (default t)"
|
||||||
(let ((sh (or (plist-get opts :shell) "/bin/bash"))
|
(let* ((sh (or (plist-get opts :shell) "/bin/bash"))
|
||||||
(buffer (or (plist-get opts :buffer) (format "*ssh[%s]*" host)))
|
(buffer (or (plist-get opts :buffer) (format "*ssh[%s]*" host)))
|
||||||
(erase? (or (plist-get opts :erase-buffer?) t))
|
(erase? (or (plist-get opts :erase-buffer?) t))
|
||||||
(cmds (format "'%s'" (mapconcat #'identity commands ";")))
|
(cmds (format "'%s'" (mapconcat #'identity commands ";")))
|
||||||
(output-buffer (get-buffer-create buffer)))
|
(output-buffer (get-buffer-create buffer)))
|
||||||
|
|
||||||
(when erase?
|
(when erase?
|
||||||
(with-current-buffer output-buffer
|
(with-current-buffer output-buffer
|
||||||
|
@ -101,9 +109,8 @@ OPTS:
|
||||||
(when (string= event "finished\n")
|
(when (string= event "finished\n")
|
||||||
(message "Commands finished. Closing SSH connection.")
|
(message "Commands finished. Closing SSH connection.")
|
||||||
;;(kill-process process)
|
;;(kill-process process)
|
||||||
))))
|
))))))
|
||||||
(message "Task started on %s -> %s" host (buffer-name output-buffer))))
|
|
||||||
|
|
||||||
|
|
||||||
(provide 'fg42/ssh)
|
(provide 'fg42/shell)
|
||||||
;;; ssh.el ends here
|
;;; ssh.el ends here
|
||||||
|
|
Loading…
Reference in New Issue