From 1d45057dda47b1601f8077f1419cbf39be6e4b67 Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Tue, 17 Oct 2023 10:46:45 +0100 Subject: [PATCH] Add some utility functions to the shell module to be used in the project interface --- core/cubes/fg42.el | 2 ++ core/fg42/project.el | 2 +- core/fg42/shell.el | 25 ++++++++++++++++--------- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/core/cubes/fg42.el b/core/cubes/fg42.el index afffc6c..e3d4e5f 100644 --- a/core/cubes/fg42.el +++ b/core/cubes/fg42.el @@ -54,6 +54,8 @@ (require 'cubes/agda) (require 'cubes/notifications) (require 'cubes/noether) +(require 'cubes/nix) +(require 'cubes/julia) (defcube fg42/editor diff --git a/core/fg42/project.el b/core/fg42/project.el index 7e6d9fe..a196bdb 100644 --- a/core/fg42/project.el +++ b/core/fg42/project.el @@ -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)))) diff --git a/core/fg42/shell.el b/core/fg42/shell.el index 22adfed..a60909f 100644 --- a/core/fg42/shell.el +++ b/core/fg42/shell.el @@ -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