--- /dev/null
+;;; 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)))
+
+
+\f
+;;; 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-"))
+\f
+;;; 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
--- /dev/null
+;;; eshell-vterm.el --- Vterm for visual commands in eshell -*- lexical-binding: t; -*-
+
+;; Author: Illia Ostapyshyn <ilya.ostapyshynNOSPAMgmail.com>
+;; Maintainer: Illia Ostapyshyn <ilya.ostapyshynNOSPAMgmail.com>
+;; 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 <https://www.gnu.org/licenses/>.
+
+;;; 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