Refactor eshell integration
This commit is contained in:
parent
8a666aedfe
commit
caae5946cf
2 changed files with 89 additions and 43 deletions
|
@ -2,8 +2,12 @@
|
|||
|
||||
(require 'eshell)
|
||||
|
||||
(defun doom--eshell-in-prompt-p (&optional offset)
|
||||
(>= (- (point) (or offset 0)) (save-excursion (eshell-bol) (point))))
|
||||
(defvar doom-eshell-buffers '() "")
|
||||
(defvar doom-eshell-height 16 "")
|
||||
(defvar-local doom-eshell-direction nil "")
|
||||
|
||||
(defun doom--eshell-outside-prompt-p (&optional offset)
|
||||
(< (point) eshell-last-output-end))
|
||||
|
||||
(defun doom--eshell-current-git-branch ()
|
||||
(let ((branch (car (loop for match in (split-string (shell-command-to-string "git branch") "\n")
|
||||
|
@ -13,61 +17,88 @@
|
|||
(concat " [" (substring branch 2) "]")
|
||||
"")))
|
||||
|
||||
;;;###autoload
|
||||
(defun doom/eshell-split ()
|
||||
(interactive)
|
||||
(select-window (split-window-vertically doom-eshell-height))
|
||||
(setq-local doom-eshell-direction 'below)
|
||||
(doom--eshell-init t))
|
||||
|
||||
;;;###autoload
|
||||
(defun doom/eshell-vsplit ()
|
||||
(interactive)
|
||||
(select-window (split-window-horizontally))
|
||||
(setq-local doom-eshell-direction 'right)
|
||||
(doom--eshell-init t))
|
||||
|
||||
;;;###autoload
|
||||
(defun doom/eshell (&optional same &rest _)
|
||||
(interactive)
|
||||
(let ((buf (get-buffer-create eshell-buffer-name)))
|
||||
(cl-assert (and buf (buffer-live-p buf)))
|
||||
(doom/popup-buffer buf)
|
||||
(with-current-buffer buf
|
||||
(unless (derived-mode-p 'eshell-mode)
|
||||
(eshell-mode)))))
|
||||
(doom--eshell-init same)
|
||||
;; (if doom-eshell-buffers
|
||||
;; (let* ((buf (car (reverse doom-eshell-buffers)))
|
||||
;; (win (get-buffer-window buf)))
|
||||
;; (if (and win (window-live-p win))
|
||||
;; (select-window win)
|
||||
;; (select-window (split-window-vertically doom-eshell-height))
|
||||
;; (evil-window-move-very-bottom)
|
||||
;; (switch-to-buffer buf t t)))
|
||||
;; (doom--eshell-init same))
|
||||
)
|
||||
|
||||
(defun doom--eshell-init (&optional same)
|
||||
(unless same (select-window (split-window)))
|
||||
(eshell (max 0 (1- (length doom-eshell-buffers))))
|
||||
(unless same
|
||||
(evil-window-move-very-bottom)
|
||||
(evil-window-set-height doom-eshell-height))
|
||||
(set-window-dedicated-p (selected-window) t))
|
||||
|
||||
;;;###autoload
|
||||
(defun doom/eshell-prompt ()
|
||||
(concat (propertize (abbreviate-file-name (eshell/pwd)) 'face 'eshell-prompt)
|
||||
(propertize (doom--eshell-current-git-branch) 'face 'font-lock-function-name-face)
|
||||
(propertize " $ " 'face 'font-lock-constant-face)))
|
||||
(propertize " λ " 'face 'font-lock-constant-face)))
|
||||
|
||||
;;;###autoload
|
||||
(defun doom/eshell-evil-append ()
|
||||
(interactive)
|
||||
(goto-char (point-max))
|
||||
(call-interactively 'evil-append))
|
||||
(goto-char eshell-last-output-end)
|
||||
(call-interactively 'evil-append-line))
|
||||
|
||||
;;;###autoload
|
||||
(defun doom/eshell-evil-append-maybe ()
|
||||
(interactive)
|
||||
(if (doom--eshell-in-prompt-p)
|
||||
(call-interactively 'evil-insert)
|
||||
(doom/eshell-append)))
|
||||
(if (doom--eshell-outside-prompt-p)
|
||||
(doom/eshell-evil-append)
|
||||
(call-interactively 'evil-append)))
|
||||
|
||||
;;;###autoload
|
||||
(defun doom/eshell-evil-prepend ()
|
||||
(interactive)
|
||||
(eshell-bol)
|
||||
(goto-char eshell-last-output-end)
|
||||
(call-interactively 'evil-insert))
|
||||
|
||||
;;;###autoload
|
||||
(defun doom/eshell-evil-prepend-maybe ()
|
||||
(interactive)
|
||||
(if (doom--eshell-in-prompt-p)
|
||||
(call-interactively 'evil-insert)
|
||||
(doom/eshell-prepend)))
|
||||
(if (doom--eshell-outside-prompt-p)
|
||||
(doom/eshell-evil-prepend)
|
||||
(call-interactively 'evil-insert)))
|
||||
|
||||
;;;###autoload
|
||||
(defun doom/eshell-evil-replace-maybe ()
|
||||
(interactive)
|
||||
(if (doom--eshell-in-prompt-p)
|
||||
(call-interactively 'evil-replace)
|
||||
(user-error "Cannot edit read-only region")))
|
||||
(if (doom--eshell-outside-prompt-p)
|
||||
(user-error "Cannot edit read-only region")
|
||||
(call-interactively 'evil-replace)))
|
||||
|
||||
;;;###autoload
|
||||
(defun doom/eshell-evil-replace-state-maybe ()
|
||||
(interactive)
|
||||
(if (doom--eshell-in-prompt-p)
|
||||
(call-interactively 'evil-replace-state)
|
||||
(user-error "Cannot edit read-only region")))
|
||||
(if (doom--eshell-outside-prompt-p)
|
||||
(user-error "Cannot edit read-only region")
|
||||
(call-interactively 'evil-replace-state)))
|
||||
|
||||
(provide 'defuns-eshell)
|
||||
;;; defuns-eshell.el ends here
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue