diff options
Diffstat (limited to 'lib/eos')
| -rw-r--r-- | lib/eos/jao-shell.el | 70 |
1 files changed, 65 insertions, 5 deletions
diff --git a/lib/eos/jao-shell.el b/lib/eos/jao-shell.el index e13e07f..8745492 100644 --- a/lib/eos/jao-shell.el +++ b/lib/eos/jao-shell.el @@ -18,11 +18,70 @@ ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see <https://www.gnu.org/licenses/>. -;;; Commentary: - -;; shell helpers - -;;; Code: +(require 'term) + +;;; term +;;;###autoload +(defvar jao-use-vterm nil) + +;;;###autoload +(defvar jao-use-eat nil) + +(defvar-local jao-term--cmd nil) + +(defvar-local jao-term--cmd nil) + +(defun jao-term--find (cmd) + (seq-find (lambda (b) + (with-current-buffer b + (and (derived-mode-p 'eat-mode 'term-mode 'vterm-mode) + (string= (or jao-term--cmd "") cmd)))) + (buffer-list))) + +(declare-function vterm nil) +(declare-function vterm-mode nil) +(defvar vterm-shell) +(defvar vterm-kill-buffer-on-exit) + +(defun jao-exec-in-vterm (cmd bname &optional no-kill) + (if (string-blank-p (or cmd "")) + (vterm) + (let ((vterm-shell cmd) + (vterm-kill-buffer-on-exit (not no-kill)) + (buff (generate-new-buffer bname))) + (switch-to-buffer buff) + (vterm-mode)))) + +;;;###autoload +(defun jao-exec-in-term (cmd &optional name no-kill) + (interactive "SCommand") + (require 'eat nil t) + (cond ((and jao-use-vterm (fboundp 'jao-exec-in-vterm)) + (jao-exec-in-vterm cmd name no-kill)) + ((and jao-use-eat (fboundp 'eat)) + (let ((eat-term-name "xterm-256color")) + (with-current-buffer (eat cmd t) + (setq-local jao-term--cmd cmd)))) + (t (ansi-term "bash" name) + (unless no-kill + (set-process-sentinel (get-buffer-process (current-buffer)) + (lambda (process event) + (when (string= event "finished\n") + (kill-buffer (process-buffer process)))))) + (setq-local jao-term--cmd cmd) + (term-send-string nil (format "%s%s\n" cmd (if no-kill "" ";exit")))))) + +;;;###autoload +(defmacro jao-def-exec-in-term (name cmd &rest prelude) + `(defun ,(intern (format "jao-term-%s" name)) (&optional term) + (interactive "P") + ,@prelude + (let ((jao-use-vterm (if term (not jao-use-vterm) jao-use-vterm))) + (if-let* ((b (jao-term--find ,cmd))) + (pop-to-buffer b) + (jao-exec-in-term ,cmd ,(format "*%s*" name)))))) + +;;; shell (defun jao-shell-cmd-lines (cmd &rest args) (let ((cmd (concat cmd " " (combine-and-quote-strings args)))) @@ -66,4 +125,5 @@ (defun jao-shell-kill-p (pr) (eq 0 (jao-shell-exec* t "killall" pr))) (provide 'jao-shell) + ;;; jao-shell.el ends here |
