From 5471dc927f98a63a4187768f28259cbb0fd5563a Mon Sep 17 00:00:00 2001 From: Andreas Gerler Date: Sun, 26 Nov 2023 16:52:53 +0100 Subject: [PATCH] add eshell-vterm Signed-off-by: Andreas Gerler --- bba.org | 6 ++ .../eshell-vterm-autoloads.el | 54 ++++++++++ .../eshell-vterm-pkg.el | 15 +++ .../eshell-vterm.el | 98 +++++++++++++++++++ 4 files changed, 173 insertions(+) create mode 100644 elpa/eshell-vterm-20221229.1328/eshell-vterm-autoloads.el create mode 100644 elpa/eshell-vterm-20221229.1328/eshell-vterm-pkg.el create mode 100644 elpa/eshell-vterm-20221229.1328/eshell-vterm.el diff --git a/bba.org b/bba.org index 4ed05f23..3cc45670 100644 --- a/bba.org +++ b/bba.org @@ -1809,6 +1809,12 @@ Bound to =C-X l != (eshell-send-input))) #+END_SRC +Run commands via vterm + +#+begin_src emacs-lisp + (defalias 'eshell/v 'eshell-exec-visual) +#+end_src + https://fuco1.github.io/2017-10-08-Using-bookmarks-with-eshell-and-docker-tramp.html #+begin_src emacs-lisp diff --git a/elpa/eshell-vterm-20221229.1328/eshell-vterm-autoloads.el b/elpa/eshell-vterm-20221229.1328/eshell-vterm-autoloads.el new file mode 100644 index 00000000..695a9dc6 --- /dev/null +++ b/elpa/eshell-vterm-20221229.1328/eshell-vterm-autoloads.el @@ -0,0 +1,54 @@ +;;; eshell-vterm-autoloads.el --- automatically extracted autoloads (do not edit) -*- lexical-binding: t -*- +;; Generated by the `loaddefs-generate' function. + +;; This file is part of GNU Emacs. + +;;; Code: + +(add-to-list 'load-path (or (and load-file-name (directory-file-name (file-name-directory load-file-name))) (car load-path))) + + + +;;; Generated autoloads from eshell-vterm.el + +(defvar eshell-vterm-mode nil "\ +Non-nil if Eshell-Vterm mode is enabled. +See the `eshell-vterm-mode' command +for a description of this minor mode. +Setting this variable directly does not take effect; +either customize it (see the info node `Easy Customization') +or call the function `eshell-vterm-mode'.") +(custom-autoload 'eshell-vterm-mode "eshell-vterm" nil) +(autoload 'eshell-vterm-mode "eshell-vterm" "\ +Use Vterm for eshell visual commands. + +This is a global minor mode. If called interactively, toggle the +`Eshell-Vterm mode' mode. If the prefix argument is positive, +enable the mode, and if it is zero or negative, disable the mode. + +If called from Lisp, toggle the mode if ARG is `toggle'. Enable +the mode if ARG is nil, omitted, or is a positive number. +Disable the mode if ARG is a negative number. + +To check whether the minor mode is enabled in the current buffer, +evaluate `(default-value \\='eshell-vterm-mode)'. + +The mode's hook is called both when the mode is enabled and when +it is disabled. + +(fn &optional ARG)" t) +(register-definition-prefixes "eshell-vterm" '("eshell-vterm-")) + +;;; End of scraped data + +(provide 'eshell-vterm-autoloads) + +;; Local Variables: +;; version-control: never +;; no-byte-compile: t +;; no-update-autoloads: t +;; no-native-compile: t +;; coding: utf-8-emacs-unix +;; End: + +;;; eshell-vterm-autoloads.el ends here diff --git a/elpa/eshell-vterm-20221229.1328/eshell-vterm-pkg.el b/elpa/eshell-vterm-20221229.1328/eshell-vterm-pkg.el new file mode 100644 index 00000000..11c89496 --- /dev/null +++ b/elpa/eshell-vterm-20221229.1328/eshell-vterm-pkg.el @@ -0,0 +1,15 @@ +(define-package "eshell-vterm" "20221229.1328" "Vterm for visual commands in eshell" + '((emacs "27.1") + (vterm "0.0.1")) + :commit "e96c30ad5e7d63b778fc3232e81b090b63b13277" :authors + '(("Illia Ostapyshyn" . "ilya.ostapyshyn@gmail.com")) + :maintainers + '(("Illia Ostapyshyn" . "ilya.ostapyshyn@gmail.com")) + :maintainer + '("Illia Ostapyshyn" . "ilya.ostapyshyn@gmail.com") + :keywords + '("eshell" "vterm" "terminals" "shell" "visual" "tools" "processes") + :url "https://github.com/iostapyshyn/eshell-vterm") +;; Local Variables: +;; no-byte-compile: t +;; End: diff --git a/elpa/eshell-vterm-20221229.1328/eshell-vterm.el b/elpa/eshell-vterm-20221229.1328/eshell-vterm.el new file mode 100644 index 00000000..0fd622e9 --- /dev/null +++ b/elpa/eshell-vterm-20221229.1328/eshell-vterm.el @@ -0,0 +1,98 @@ +;;; eshell-vterm.el --- Vterm for visual commands in eshell -*- lexical-binding: t; -*- + +;; Author: Illia Ostapyshyn +;; Maintainer: Illia Ostapyshyn +;; Created: 2021-06-29 +;; Version: 0.1 +;; Package-Requires: ((emacs "27.1") (vterm "0.0.1")) +;; Keywords: eshell, vterm, terminals, shell, visual, tools, processes +;; URL: https://github.com/iostapyshyn/eshell-vterm + +;; This file is not part of GNU Emacs. + +;; This file is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 2, or (at your option) +;; any later version. + +;; This file is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see . + +;;; Commentary: + +;; This package provides a global minor mode allowing eshell to use +;; vterm for visual commands. + +;;; Code: + +(require 'vterm) +(require 'em-term) +(require 'esh-ext) + +(defvar eshell-parent-buffer) + +(defun eshell-vterm-exec-visual (&rest args) + "Run the specified PROGRAM in a terminal emulation buffer. +ARGS are passed to the program. At the moment, no piping of input is +allowed. In case ARGS is nil, a new VTerm session is created." + (if args + (let* (eshell-interpreter-alist + (interp (eshell-find-interpreter (car args) (cdr args))) + (program (car interp)) + (args (flatten-tree + (eshell-stringify-list (append (cdr interp) + (cdr args))))) + (args (mapconcat #'shell-quote-argument args " ")) + (term-buf (generate-new-buffer + (concat "*" (file-name-nondirectory program) "*"))) + (eshell-buf (current-buffer)) + (vterm-shell (concat (shell-quote-argument + (file-local-name program)) + " " args))) + (save-current-buffer + (switch-to-buffer term-buf) + (vterm-mode) + (setq-local eshell-parent-buffer eshell-buf) + (let ((proc (get-buffer-process term-buf))) + (if (and proc (eq 'run (process-status proc))) + (set-process-sentinel proc #'eshell-vterm-sentinel) + (error "Failed to invoke visual command"))))) + (vterm '(4))) ; Start a new session + nil) + +(defun eshell-vterm-sentinel (proc msg) + "Clean up the buffer visiting PROC with message MSG. +If `eshell-destroy-buffer-when-process-dies' is non-nil, destroy +the buffer." + (let ((vterm-kill-buffer-on-exit nil)) + (vterm--sentinel proc msg)) ;; First call the normal term sentinel. + (when eshell-destroy-buffer-when-process-dies + (let ((proc-buf (process-buffer proc))) + (when (and proc-buf (buffer-live-p proc-buf) + (not (eq 'run (process-status proc))) + (= (process-exit-status proc) 0)) + (if (eq (current-buffer) proc-buf) + (let ((buf (and (boundp 'eshell-parent-buffer) + eshell-parent-buffer + (buffer-live-p eshell-parent-buffer) + eshell-parent-buffer))) + (if buf + (switch-to-buffer buf)))) + (kill-buffer proc-buf))))) + +;;;###autoload +(define-minor-mode eshell-vterm-mode + "Use Vterm for eshell visual commands." + :global t + :group 'eshell-vterm + (if eshell-vterm-mode + (advice-add #'eshell-exec-visual :override #'eshell-vterm-exec-visual) + (advice-remove #'eshell-exec-visual #'eshell-vterm-exec-visual))) + +(provide 'eshell-vterm) +;;; eshell-vterm.el ends here -- 2.47.3