tools/eshell: spawn new eshell on split window
This commit is contained in:
parent
57065c4a71
commit
a067500ef2
1 changed files with 18 additions and 26 deletions
|
@ -25,13 +25,6 @@
|
||||||
;; Library
|
;; Library
|
||||||
;;
|
;;
|
||||||
|
|
||||||
(defun +eshell--add-buffer (buf)
|
|
||||||
(ring-remove+insert+extend +eshell-buffers buf))
|
|
||||||
|
|
||||||
(defun +eshell--remove-buffer (buf)
|
|
||||||
(when-let* ((idx (ring-member +eshell-buffers buf)))
|
|
||||||
(ring-remove +eshell-buffers idx)))
|
|
||||||
|
|
||||||
(defun +eshell--current-git-branch ()
|
(defun +eshell--current-git-branch ()
|
||||||
(let ((branch (car (cl-loop for match in (split-string (shell-command-to-string "git branch") "\n")
|
(let ((branch (car (cl-loop for match in (split-string (shell-command-to-string "git branch") "\n")
|
||||||
if (string-match-p "^\*" match)
|
if (string-match-p "^\*" match)
|
||||||
|
@ -40,11 +33,12 @@
|
||||||
(format " [%s]" (substring branch 2))
|
(format " [%s]" (substring branch 2))
|
||||||
"")))
|
"")))
|
||||||
|
|
||||||
(defun +eshell-delete-window ()
|
;;;###autoload
|
||||||
(if (one-window-p)
|
(defun +eshell-prompt ()
|
||||||
(unless (doom-real-buffer-p (progn (previous-buffer) (current-buffer)))
|
"Generate the prompt string for eshell. Use for `eshell-prompt-function'."
|
||||||
(switch-to-buffer (doom-fallback-buffer)))
|
(concat (propertize (abbreviate-file-name (eshell/pwd)) 'face '+eshell-prompt-pwd)
|
||||||
(delete-window)))
|
(propertize (+eshell--current-git-branch) 'face '+eshell-prompt-git-branch)
|
||||||
|
(propertize " λ " 'face '+eshell-prompt-char)))
|
||||||
|
|
||||||
(defun +eshell-get-or-create-buffer ()
|
(defun +eshell-get-or-create-buffer ()
|
||||||
(or (cl-loop for buf in (ring-elements +eshell-buffers)
|
(or (cl-loop for buf in (ring-elements +eshell-buffers)
|
||||||
|
@ -53,13 +47,6 @@
|
||||||
return buf)
|
return buf)
|
||||||
(generate-new-buffer +eshell-buffer-name)))
|
(generate-new-buffer +eshell-buffer-name)))
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun +eshell-prompt ()
|
|
||||||
"Generate the prompt string for eshell. Use for `eshell-prompt-function'."
|
|
||||||
(concat (propertize (abbreviate-file-name (eshell/pwd)) 'face '+eshell-prompt-pwd)
|
|
||||||
(propertize (+eshell--current-git-branch) 'face '+eshell-prompt-git-branch)
|
|
||||||
(propertize " λ " 'face '+eshell-prompt-char)))
|
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;; Commands
|
;; Commands
|
||||||
|
@ -72,7 +59,9 @@
|
||||||
(let ((buf (+eshell-get-or-create-buffer)))
|
(let ((buf (+eshell-get-or-create-buffer)))
|
||||||
(with-current-buffer buf
|
(with-current-buffer buf
|
||||||
(unless (eq major-mode 'eshell-mode) (eshell-mode)))
|
(unless (eq major-mode 'eshell-mode) (eshell-mode)))
|
||||||
(switch-to-buffer buf)
|
(if (eq major-mode 'eshell-mode)
|
||||||
|
(pop-to-buffer buf)
|
||||||
|
(switch-to-buffer buf))
|
||||||
(when command
|
(when command
|
||||||
(+eshell-run-command command))))
|
(+eshell-run-command command))))
|
||||||
|
|
||||||
|
@ -120,12 +109,17 @@ module to be loaded."
|
||||||
;; Hooks
|
;; Hooks
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
(defun +eshell--add-buffer (buf)
|
||||||
|
(ring-remove+insert+extend +eshell-buffers buf))
|
||||||
|
|
||||||
|
(defun +eshell--remove-buffer (buf)
|
||||||
|
(when-let* ((idx (ring-member +eshell-buffers buf)))
|
||||||
|
(ring-remove +eshell-buffers idx)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +eshell|init ()
|
(defun +eshell|init ()
|
||||||
"Keep track of eshell buffers."
|
"Keep track of eshell buffers."
|
||||||
(let ((buf (current-buffer)))
|
(let ((buf (current-buffer)))
|
||||||
(remove-hook 'kill-buffer-query-functions #'doom|protect-visible-buffers t)
|
|
||||||
(add-hook 'kill-buffer-hook #'+eshell-delete-window nil t)
|
|
||||||
(dolist (buf (ring-elements +eshell-buffers))
|
(dolist (buf (ring-elements +eshell-buffers))
|
||||||
(unless (buffer-live-p buf)
|
(unless (buffer-live-p buf)
|
||||||
(+eshell--remove-buffer buf)))
|
(+eshell--remove-buffer buf)))
|
||||||
|
@ -155,15 +149,13 @@ delete."
|
||||||
(delete-char arg)))
|
(delete-char arg)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +eshell/split-below ()
|
(defun +eshell/split ()
|
||||||
"Create a new eshell window below the current one."
|
|
||||||
(interactive)
|
(interactive)
|
||||||
(select-window (split-window-vertically))
|
(select-window (split-window-vertically))
|
||||||
(+eshell/open))
|
(+eshell/open))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +eshell/split-right ()
|
(defun +eshell/vsplit ()
|
||||||
"Create a new eshell window to the right of the current one."
|
|
||||||
(interactive)
|
(interactive)
|
||||||
(select-window (split-window-horizontally))
|
(select-window (split-window-horizontally))
|
||||||
(+eshell/open))
|
(+eshell/open))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue