Better eshell terminal windows
Now we don't re-open eshell windows, but just pop to it. Also we have a send-command that I can programmatically send commands to an open window.
This commit is contained in:
parent
75a7db65c1
commit
50b5be3ec8
2 changed files with 43 additions and 12 deletions
|
@ -1262,19 +1262,47 @@ Now that I often need to pop into remote systems to run a shell or commands, I c
|
||||||
** Shell There
|
** Shell There
|
||||||
The basis for distinguishing a shell is its /parent location/. Before starting =eshell=, we make a small window, set the buffer name (using the [[elisp:(describe-variable 'eshell-buffer-name)][eshell-buffer-name]]):
|
The basis for distinguishing a shell is its /parent location/. Before starting =eshell=, we make a small window, set the buffer name (using the [[elisp:(describe-variable 'eshell-buffer-name)][eshell-buffer-name]]):
|
||||||
#+begin_src emacs-lisp
|
#+begin_src emacs-lisp
|
||||||
(defun eshell-there (parent)
|
(defun eshell--buffer-from-dir (dir)
|
||||||
"Open an eshell session in a PARENT directory.
|
"Return buffer name of an Eshell based on DIR."
|
||||||
The window is smaller and named after this directory."
|
(format "*eshell: %s*"
|
||||||
(let* ((name (thread-first parent
|
(thread-first dir
|
||||||
(split-string "/" t)
|
(split-string "/" t)
|
||||||
(last)
|
(last)
|
||||||
(car)))
|
(car))))
|
||||||
(height (/ (window-total-height) 3))
|
|
||||||
(default-directory parent))
|
(defun eshell-there (parent)
|
||||||
|
"Open an eshell session in a PARENT directory.
|
||||||
|
The window is smaller and named after this directory.
|
||||||
|
If an Eshell is already present that has been named
|
||||||
|
after PARENT, pop to that buffer instead."
|
||||||
|
(if-let* ((term-name (eshell--buffer-from-dir parent))
|
||||||
|
(buf-name (seq-contains (buffer-list) term-name
|
||||||
|
(lambda (a b) (string-equal (buffer-name b) a)))))
|
||||||
|
(pop-to-buffer buf)
|
||||||
|
|
||||||
|
(let* ((default-directory parent)
|
||||||
|
(height (/ (window-total-height) 3)))
|
||||||
(split-window-vertically (- height))
|
(split-window-vertically (- height))
|
||||||
(other-window 1)
|
(other-window 1)
|
||||||
(setq eshell-buffer-name (format "*eshell: %s*" name))
|
(setq eshell-buffer-name term-name)
|
||||||
(eshell)))
|
(eshell))))
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
And we can run a command in an opened Eshell buffer:
|
||||||
|
#+begin_src emacs-lisp
|
||||||
|
(defun ha-eshell-send (command &optional dir)
|
||||||
|
"Send COMMAND to the Eshell buffer named with DIR.
|
||||||
|
The Eshell may have moved away from the directory originally
|
||||||
|
opened with DIR, but it should have the name of the buffer.
|
||||||
|
See `eshell--buffer-from-dir'."
|
||||||
|
(interactive "sCommand to Send: ")
|
||||||
|
(unless dir
|
||||||
|
(setq dir (projectile-project-root)))
|
||||||
|
(save-window-excursion
|
||||||
|
(eshell-there dir)
|
||||||
|
(goto-char (point-max))
|
||||||
|
(insert command)
|
||||||
|
(eshell-send-input)))
|
||||||
#+end_src
|
#+end_src
|
||||||
** Shell Here
|
** Shell Here
|
||||||
This version of the =eshell= bases the location on the current buffer’s parent directory:
|
This version of the =eshell= bases the location on the current buffer’s parent directory:
|
||||||
|
|
|
@ -456,10 +456,13 @@ If I end a command with a =|v=, it sends the compile command to a vterm session
|
||||||
(ha-shell-send command project-dir)))
|
(ha-shell-send command project-dir)))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
And what about sending stuff to Eshell as well?
|
And what about sending the command to Eshell as well?
|
||||||
#+begin_src emacs-lisp
|
#+begin_src emacs-lisp
|
||||||
(defvar rx-compile-to-eshell (rx "|" (0+ space) "s" (0+ space) line-end))
|
(defvar rx-compile-to-eshell (rx "|" (0+ space) "s" (0+ space) line-end))
|
||||||
|
|
||||||
|
(defun ha-compile-eshell (full-command)
|
||||||
|
(let ((command (replace-regexp-in-string rx-compile-to-eshell "" full-command)))
|
||||||
|
(ha-shell-send command project-dir)))
|
||||||
#+end_src
|
#+end_src
|
||||||
And let’s add it to the Project leader:
|
And let’s add it to the Project leader:
|
||||||
#+begin_src emacs-lisp
|
#+begin_src emacs-lisp
|
||||||
|
|
Loading…
Reference in a new issue