Commit 6e6635b54307

Vincent Demeester <vincent@sbr.pm>
2022-09-12 14:51:58
tools/emacs: add and bind a "run in project vterm"…
… the idea is to be able to run command interactively on an existing (or to-be-created) vterm shell. The goal is to easily be able to run `gh pr create` for GitHub PRs for example. Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent daf4a10
Changed files (1)
tools
tools/emacs/config/config-projects.el
@@ -5,7 +5,8 @@
 
 (use-package project
   :bind (("C-x p v" . vde-project-magit-status)
-         ("C-x p s" . vde-project-vterm))
+         ("C-x p s" . vde-project-vterm)
+         ("C-x p X" . vde/run-in-project-vterm))
   :config
 
   (setq vde/project-local-identifier '(".project")) ;; "go.mod"
@@ -46,7 +47,7 @@
     (interactive)
     (magit-status (vde-project--project-current)))
 
-  (defun vde-project-vterm ()
+  (defun vde-project-vterm (&optional command)
     "Run `vterm' on project.
 If a buffer already exists for running a vterm shell in the project's root,
 switch to it. Otherwise, create a new vterm shell."
@@ -60,7 +61,17 @@ switch to it. Otherwise, create a new vterm shell."
           (vterm default-project-vterm-name)
           (with-current-buffer vterm-buffer
             (vterm-send-string cd-cmd)
-            (vterm-send-return)))))))
+            (vterm-send-return))))
+      (when command
+        (vterm-send-string command)
+        (vterm-send-return))))
+  (defun vde/run-in-project-vterm ()
+    (interactive)
+    (let* ((default-directory (vde-project--project-current))
+           (default-project-vterm-name (project-prefixed-buffer-name "vterm"))
+           (vterm-buffer (get-buffer default-project-vterm-name)))
+      (vde-project-vterm (read-string "Command: "))))
+  )
 
 (provide 'config-projects)
 ;;; config-projects.el ends here