tools/eshell: bugfix + minor refactor
+ Change default name for (doom) eshell buffers + Fix eshell splitting commands (referring to incorrect subcommand) + Correct aliases (using wrong commands) + +eshell/run => +eshell/open + +eshell/popup => +eshell/open-popup + +eshell/tab => +eshell/open-workspace + +eshell/prompt => +eshell-prompt (conform to naming convention)
This commit is contained in:
parent
e8ff048c9b
commit
0479ac3b88
3 changed files with 60 additions and 59 deletions
|
@ -1,27 +1,32 @@
|
|||
;;; tools/eshell/autoload/eshell.el -*- lexical-binding: t; -*-
|
||||
|
||||
(require 'eshell)
|
||||
(defvar +eshell-buffers ()
|
||||
"List of open eshell buffers.")
|
||||
|
||||
(defvar +eshell-buffer-name "*doom:eshell*"
|
||||
"The name to use for custom eshell buffers. This only affects `+eshell/open',
|
||||
`+eshell/open-popup' and `+eshell/open-workspace'.")
|
||||
|
||||
;;;###autoload
|
||||
(defun +eshell/run ()
|
||||
(defun +eshell/open ()
|
||||
"Open eshell in the current buffer."
|
||||
(interactive)
|
||||
(let ((buf (generate-new-buffer eshell-buffer-name)))
|
||||
(let ((buf (generate-new-buffer +eshell-buffer-name)))
|
||||
(with-current-buffer buf
|
||||
(unless (eq major-mode 'eshell-mode) (eshell-mode)))
|
||||
(pop-to-buffer-same-window buf)))
|
||||
(switch-to-buffer buf)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +eshell/popup ()
|
||||
(defun +eshell/open-popup ()
|
||||
"Open eshell in a popup window."
|
||||
(interactive)
|
||||
(let ((buf (get-buffer-create "*eshell:popup*")))
|
||||
(let ((buf (get-buffer-create +eshell-buffer-name)))
|
||||
(with-current-buffer buf
|
||||
(unless (eq major-mode 'eshell-mode) (eshell-mode)))
|
||||
(doom-popup-buffer buf)))
|
||||
(doom-popup-buffer buf '(:autokill t) t)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +eshell/tab ()
|
||||
(defun +eshell/open-workspace ()
|
||||
"Open eshell in a separate workspace. Requires the (:feature workspaces)
|
||||
module to be loaded."
|
||||
(interactive)
|
||||
|
@ -29,12 +34,31 @@ module to be loaded."
|
|||
(user-error ":feature workspaces is required, but disabled"))
|
||||
(unless (+workspace-get "eshell" t)
|
||||
(+workspace/new "eshell"))
|
||||
(if-let (buf (cl-find-if (lambda (it) (string-match-p "^\\*eshell" (buffer-name (window-buffer it))))
|
||||
(if-let (buf (cl-find-if (lambda (it) (string-match-p "^\\*doom:eshell" (buffer-name (window-buffer it))))
|
||||
(doom-visible-windows)))
|
||||
(select-window (get-buffer-window buf))
|
||||
(+eshell/run))
|
||||
(+eshell/open))
|
||||
(doom/workspace-display))
|
||||
|
||||
|
||||
;; --- Hooks ------------------------------
|
||||
|
||||
;;;###autoload
|
||||
(defun +eshell|init ()
|
||||
"Keep track of eshell buffers."
|
||||
(cl-pushnew (current-buffer) +eshell-buffers :test #'eq))
|
||||
|
||||
;;;###autoload
|
||||
(defun +eshell|cleanup ()
|
||||
"Close window (or workspace) on quit."
|
||||
(setq +eshell-buffers (delete (current-buffer) +eshell-buffers))
|
||||
(when (and (featurep! :feature workspaces)
|
||||
(string= "eshell" (+workspace-current-name)))
|
||||
(+workspace/delete "eshell")))
|
||||
|
||||
|
||||
;; --- Keybindings ------------------------
|
||||
|
||||
;;;###autoload
|
||||
(defun +eshell/quit-or-delete-char (arg)
|
||||
(interactive "p")
|
||||
|
@ -57,16 +81,16 @@ module to be loaded."
|
|||
(defun +eshell/split ()
|
||||
(interactive)
|
||||
(select-window (split-window-vertically))
|
||||
(+eshell:run))
|
||||
(+eshell/open))
|
||||
|
||||
;;;###autoload
|
||||
(defun +eshell/vsplit ()
|
||||
(interactive)
|
||||
(select-window (split-window-horizontally))
|
||||
(+eshell:run))
|
||||
(+eshell/open))
|
||||
|
||||
;;;###autoload
|
||||
(defun +eshell/prompt ()
|
||||
(defun +eshell-prompt ()
|
||||
(concat (propertize (abbreviate-file-name (eshell/pwd)) 'face 'eshell-prompt)
|
||||
(propertize (+eshell--current-git-branch) 'face 'font-lock-function-name-face)
|
||||
(propertize " λ " 'face 'font-lock-constant-face)))
|
||||
|
|
|
@ -6,5 +6,5 @@
|
|||
(interactive "<fsh><!>")
|
||||
(if bang
|
||||
(+eshell/run)
|
||||
(+eshell/popup)))
|
||||
(+eshell/open-popup)))
|
||||
|
||||
|
|
|
@ -3,14 +3,12 @@
|
|||
;; This is highly experimental. I don't use eshell often, so this may need work.
|
||||
|
||||
;; see:
|
||||
;; + `+eshell/run': open in current buffer
|
||||
;; + `+eshell/tab': open in separate tab (requires :feature workspaces)
|
||||
;; + `+eshell/popup': open in a popup
|
||||
|
||||
(defvar +eshell-buffers '()
|
||||
"TODO")
|
||||
;; + `+eshell/open': open in current buffer
|
||||
;; + `+eshell/open-popup': open in a popup
|
||||
;; + `+eshell/open-workspace': open in separate tab (requires :feature workspaces)
|
||||
|
||||
(def-package! eshell ; built-in
|
||||
:commands eshell-mode
|
||||
:init
|
||||
(setq eshell-directory-name (concat doom-cache-dir "/eshell")
|
||||
eshell-scroll-to-bottom-on-input 'all
|
||||
|
@ -19,7 +17,7 @@
|
|||
eshell-kill-processes-on-exit t
|
||||
;; em-prompt
|
||||
eshell-prompt-regexp "^.* λ "
|
||||
eshell-prompt-function #'+eshell/prompt
|
||||
eshell-prompt-function #'+eshell-prompt
|
||||
;; em-glob
|
||||
eshell-glob-case-insensitive t
|
||||
eshell-error-if-no-glob t
|
||||
|
@ -27,17 +25,20 @@
|
|||
eshell-aliases-file (concat doom-local-dir ".eshell-aliases"))
|
||||
|
||||
:config
|
||||
(set! :popup "^\\*eshell:popup\\*$" :regexp t :size 25)
|
||||
(set! :evil-state 'eshell-mode 'insert)
|
||||
|
||||
;; Keep track of open eshell buffers
|
||||
(add-hook 'eshell-mode-hook #'+eshell|init)
|
||||
(add-hook 'eshell-exit-hook #'+eshell|cleanup)
|
||||
|
||||
(after! em-term
|
||||
;; Visual commands require a proper terminal. Eshell can't handle that, so it
|
||||
;; delegates these commands to a term buffer.
|
||||
(nconc eshell-visual-commands '("tmux" "htop" "bash" "zsh" "fish" "vim" "nvim"))
|
||||
(setq eshell-visual-subcommands '(("git" "log" "l" "diff" "show"))))
|
||||
|
||||
(defun +eshell|keymap-setup ()
|
||||
"Setup eshell keybindings. This must be done in a hook because eshell
|
||||
(defun +eshell|init-keymap ()
|
||||
"Setup eshell keybindings. This must be done in a hook because eshell-mode
|
||||
redefines its keys every time `eshell-mode' is enabled."
|
||||
(map! :map eshell-mode-map
|
||||
:n "i" #'+eshell/evil-prepend-maybe
|
||||
|
@ -48,37 +49,23 @@ redefines its keys every time `eshell-mode' is enabled."
|
|||
:n "R" #'+eshell/evil-replace-state-maybe
|
||||
:n "c" #'+eshell/evil-change
|
||||
:n "C" #'+eshell/evil-change-line
|
||||
:i "<tab>" #'eshell-pcomplete
|
||||
:i "C-u" #'eshell-kill-input
|
||||
:i [tab] #'eshell-pcomplete
|
||||
:i "SPC" #'self-insert-command
|
||||
:i "C-u" #'eshell-kill-input
|
||||
:i "C-a" #'eshell-bol
|
||||
:i "C-d" #'+eshell/quit-or-delete-char
|
||||
:i "C-k" #'kill-line
|
||||
:i "C-p" #'eshell-previous-input
|
||||
:i "<up>" #'eshell-previous-input
|
||||
:i "C-n" #'eshell-previous-input
|
||||
:i "<down>" #'eshell-previous-input
|
||||
:i "C-n" #'eshell-next-input
|
||||
:i "<down>" #'eshell-next-input
|
||||
:m "<return>" #'+eshell/evil-append
|
||||
:n [remap evil-window-split] #'+eshell/split
|
||||
:n [remap evil-window-vsplit] #'+eshell/vsplit
|
||||
:n [remap evil-record-macro] #'eshell-life-is-too-much
|
||||
[remap doom/close-window-or-tab] #'eshell-life-is-too-much))
|
||||
(add-hook 'eshell-mode-hook #'+eshell|keymap-setup)
|
||||
|
||||
(defun +eshell|cleanup ()
|
||||
"Close window (or workspace) on quit."
|
||||
(setq +eshell-buffers (delete (current-buffer) +eshell-buffers))
|
||||
(cond ((doom-popup-p)
|
||||
(delete-window))
|
||||
((and (featurep! :feature workspaces)
|
||||
(string= "eshell" (+workspace-current-name)))
|
||||
(+workspace/close-window-or-workspace))))
|
||||
(add-hook 'eshell-exit-hook #'+eshell|cleanup)
|
||||
|
||||
(defun +eshell|init ()
|
||||
"Keep track of eshell buffers."
|
||||
(add-to-list '+eshell-buffers (current-buffer)))
|
||||
(add-hook 'eshell-mode-hook #'+eshell|init)
|
||||
:n [remap evil-window-split] #'+eshell/split
|
||||
:n [remap evil-window-vsplit] #'+eshell/vsplit
|
||||
:n [remap evil-record-macro] #'eshell-life-is-too-much
|
||||
[remap kill-this-buffer] #'eshell-life-is-too-much
|
||||
[remap +workspace/close-window-or-workspace] #'eshell-life-is-too-much))
|
||||
(add-hook 'eshell-mode-hook #'+eshell|init-keymap)
|
||||
|
||||
(add-hook! eshell-mode
|
||||
(add-hook 'evil-insert-state-exit-hook #'hl-line-mode nil t)
|
||||
|
@ -91,15 +78,5 @@ redefines its keys every time `eshell-mode' is enabled."
|
|||
("ll" "ls -l")
|
||||
("la" "ls -la")
|
||||
("g" "hub")
|
||||
("gs" "hub status --oneline .")
|
||||
("gss" "hub status --oneline")))
|
||||
|
||||
;; Custom commands
|
||||
;; (defun eshell/e (file)
|
||||
;; (eshell-eval (cond ((doom/popup-p)
|
||||
;; (doom/popup-save (find-file file))
|
||||
;; 0)
|
||||
;; (t (find-file file)
|
||||
;; 0))))
|
||||
)
|
||||
("gs" "hub status --short ."))))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue