Rewrite eshell config
This commit is contained in:
parent
2672d4b4cd
commit
9c2e59e231
4 changed files with 105 additions and 44 deletions
|
@ -3,8 +3,22 @@
|
||||||
(require 'eshell)
|
(require 'eshell)
|
||||||
|
|
||||||
(defvar doom-eshell-buffers '() "")
|
(defvar doom-eshell-buffers '() "")
|
||||||
(defvar doom-eshell-height 16 "")
|
|
||||||
(defvar-local doom-eshell-direction nil "")
|
;;;###autoload
|
||||||
|
(defun doom|eshell-cleanup ()
|
||||||
|
(when (eq major-mode 'eshell-mode)
|
||||||
|
(setq doom-eshell-buffers (delete (current-buffer) doom-eshell-buffers))
|
||||||
|
(cond ((doom/popup-p)
|
||||||
|
(delete-window))
|
||||||
|
((string= "eshell" (wg-workgroup-name (wg-current-workgroup t)))
|
||||||
|
(if (one-window-p)
|
||||||
|
(doom:workgroup-delete)
|
||||||
|
(delete-window))))))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun doom|eshell-init ()
|
||||||
|
(when (eq major-mode 'eshell-mode)
|
||||||
|
(add-to-list 'doom-eshell-buffers (current-buffer))))
|
||||||
|
|
||||||
(defun doom--eshell-outside-prompt-p (&optional offset)
|
(defun doom--eshell-outside-prompt-p (&optional offset)
|
||||||
(< (point) eshell-last-output-end))
|
(< (point) eshell-last-output-end))
|
||||||
|
@ -20,39 +34,14 @@
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom/eshell-split ()
|
(defun doom/eshell-split ()
|
||||||
(interactive)
|
(interactive)
|
||||||
(select-window (split-window-vertically doom-eshell-height))
|
(select-window (split-window-vertically))
|
||||||
(setq-local doom-eshell-direction 'below)
|
(doom:eshell))
|
||||||
(doom--eshell-init t))
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom/eshell-vsplit ()
|
(defun doom/eshell-vsplit ()
|
||||||
(interactive)
|
(interactive)
|
||||||
(select-window (split-window-horizontally))
|
(select-window (split-window-horizontally))
|
||||||
(setq-local doom-eshell-direction 'right)
|
(doom:eshell))
|
||||||
(doom--eshell-init t))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/eshell (&optional same &rest _)
|
|
||||||
(interactive)
|
|
||||||
(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
|
;;;###autoload
|
||||||
(defun doom/eshell-prompt ()
|
(defun doom/eshell-prompt ()
|
||||||
|
@ -60,6 +49,39 @@
|
||||||
(propertize (doom--eshell-current-git-branch) 'face 'font-lock-function-name-face)
|
(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 (autoload 'doom:eshell "defuns-eshell" nil t)
|
||||||
|
(evil-define-command doom:eshell (&optional bang)
|
||||||
|
"Create a shell in the current buffer. If BANG, use a popup buffer."
|
||||||
|
(interactive "<!>")
|
||||||
|
(let ((buf (if bang
|
||||||
|
(get-buffer-create "*eshell:popup*")
|
||||||
|
(generate-new-buffer eshell-buffer-name))))
|
||||||
|
(with-current-buffer buf
|
||||||
|
(unless (eq major-mode 'eshell-mode) (eshell-mode)))
|
||||||
|
(if bang
|
||||||
|
(doom/popup-buffer buf)
|
||||||
|
(pop-to-buffer-same-window buf))))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun doom/eshell-tab ()
|
||||||
|
"Create a separate tab for the shell."
|
||||||
|
(interactive)
|
||||||
|
(unless (wg-switch-to-workgroup (wg-get-workgroup "eshell" t) t)
|
||||||
|
(doom:tab-create nil "eshell"))
|
||||||
|
(let ((buf (--find (string-match-p "^\\*eshell" (buffer-name (window-buffer it)))
|
||||||
|
(doom/get-visible-windows))))
|
||||||
|
(if buf
|
||||||
|
(select-window (get-buffer-window buf))
|
||||||
|
(doom:eshell))
|
||||||
|
(doom/workgroup-display)))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun doom/eshell-frame ()
|
||||||
|
"Create a separate frame for the shell."
|
||||||
|
(interactive)
|
||||||
|
(doom/new-frame)
|
||||||
|
(doom:eshell))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom/eshell-evil-append ()
|
(defun doom/eshell-evil-append ()
|
||||||
(interactive)
|
(interactive)
|
||||||
|
@ -100,5 +122,19 @@
|
||||||
(user-error "Cannot edit read-only region")
|
(user-error "Cannot edit read-only region")
|
||||||
(call-interactively 'evil-replace-state)))
|
(call-interactively 'evil-replace-state)))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun doom/eshell-evil-change ()
|
||||||
|
(interactive)
|
||||||
|
(when (doom--eshell-outside-prompt-p)
|
||||||
|
(goto-char eshell-last-output-end))
|
||||||
|
(call-interactively 'evil-change))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun doom/eshell-evil-change-line ()
|
||||||
|
(interactive)
|
||||||
|
(when (doom--eshell-outside-prompt-p)
|
||||||
|
(goto-char eshell-last-output-end))
|
||||||
|
(call-interactively 'evil-change-line))
|
||||||
|
|
||||||
(provide 'defuns-eshell)
|
(provide 'defuns-eshell)
|
||||||
;;; defuns-eshell.el ends here
|
;;; defuns-eshell.el ends here
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
;;; module-eshell.el --- -*- no-byte-compile: t; -*-
|
;;; module-eshell.el --- -*- no-byte-compile: t; -*-
|
||||||
|
|
||||||
|
;; see:
|
||||||
|
;; + `doom:eshell' (open in current buffer or popup)
|
||||||
|
;; + `doom/eshell-tab' (open in separate tab)
|
||||||
|
;; + `doom/eshell-frame' (open in separate frame)
|
||||||
|
|
||||||
(use-package eshell
|
(use-package eshell
|
||||||
:init
|
:init
|
||||||
(setq eshell-directory-name (concat doom-temp-dir "/eshell")
|
(setq eshell-directory-name (concat doom-temp-dir "/eshell")
|
||||||
|
@ -16,8 +21,11 @@
|
||||||
|
|
||||||
:config
|
:config
|
||||||
(evil-set-initial-state 'eshell-mode 'insert)
|
(evil-set-initial-state 'eshell-mode 'insert)
|
||||||
|
(def-popup! "^\\*eshell:popup\\*$" :regexp t :align below :size 25 :select t)
|
||||||
|
|
||||||
(defun doom|eshell-keymap-setup ()
|
(defun doom|eshell-keymap-setup ()
|
||||||
|
"Setup eshell keybindings. This must be done in a hook because eshell
|
||||||
|
redefines its keys every time `eshell-mode' is enabled."
|
||||||
(map! :map eshell-mode-map
|
(map! :map eshell-mode-map
|
||||||
:n "i" 'doom/eshell-evil-prepend-maybe
|
:n "i" 'doom/eshell-evil-prepend-maybe
|
||||||
:n "I" 'doom/eshell-evil-prepend
|
:n "I" 'doom/eshell-evil-prepend
|
||||||
|
@ -25,20 +33,16 @@
|
||||||
:n "A" 'doom/eshell-evil-append
|
:n "A" 'doom/eshell-evil-append
|
||||||
:n "r" 'doom/eshell-evil-replace-maybe
|
:n "r" 'doom/eshell-evil-replace-maybe
|
||||||
:n "R" 'doom/eshell-evil-replace-state-maybe
|
:n "R" 'doom/eshell-evil-replace-state-maybe
|
||||||
|
:n "c" 'doom/eshell-evil-change
|
||||||
|
:n "C" 'doom/eshell-evil-change-line
|
||||||
|
:i "<tab>" 'eshell-pcomplete
|
||||||
:i "C-u" 'eshell-kill-input
|
:i "C-u" 'eshell-kill-input
|
||||||
:i "SPC" 'self-insert-command
|
:i "SPC" 'self-insert-command
|
||||||
:m "<return>" 'doom/eshell-evil-append
|
:m "<return>" 'doom/eshell-evil-append
|
||||||
:n [remap doom/evil-window-split] 'doom/eshell-split
|
:n [remap evil-window-split] 'doom/eshell-split
|
||||||
:n [remap doom/evil-window-vsplit] 'doom/eshell-vsplit))
|
:n [remap evil-window-vsplit] 'doom/eshell-vsplit
|
||||||
|
:n [remap evil-record-macro] 'eshell-life-is-too-much
|
||||||
(defun doom|eshell-init ()
|
[remap doom/close-window-or-tab] 'eshell-life-is-too-much))
|
||||||
(when (eq major-mode 'eshell-mode)
|
|
||||||
(add-to-list 'doom-eshell-buffers (current-buffer))))
|
|
||||||
|
|
||||||
(defun doom|eshell-cleanup ()
|
|
||||||
(when (eq major-mode 'eshell-mode)
|
|
||||||
(setq doom-eshell-buffers (delete (current-buffer) doom-eshell-buffers))
|
|
||||||
(delete-window)))
|
|
||||||
|
|
||||||
;; Close window on exit
|
;; Close window on exit
|
||||||
(add-hook 'eshell-exit-hook 'doom|eshell-cleanup)
|
(add-hook 'eshell-exit-hook 'doom|eshell-cleanup)
|
||||||
|
@ -46,7 +50,28 @@
|
||||||
|
|
||||||
(add-hook 'eshell-mode-hook 'doom|eshell-keymap-setup)
|
(add-hook 'eshell-mode-hook 'doom|eshell-keymap-setup)
|
||||||
(add-hook 'eshell-mode-hook 'doom-hide-mode-line-mode)
|
(add-hook 'eshell-mode-hook 'doom-hide-mode-line-mode)
|
||||||
(add-hook 'eshell-mode-hook 'hl-line-mode))
|
|
||||||
|
(add-hook! eshell-mode
|
||||||
|
(add-hook 'evil-insert-state-exit-hook 'hl-line-mode nil t)
|
||||||
|
(add-hook 'evil-insert-state-entry-hook (lambda () (hl-line-mode -1)) nil t))
|
||||||
|
|
||||||
|
;; Aliases
|
||||||
|
(setq eshell-command-aliases-list
|
||||||
|
'(("q" "exit")
|
||||||
|
("l" "ls -1")
|
||||||
|
("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)))))
|
||||||
|
|
||||||
(provide 'module-eshell)
|
(provide 'module-eshell)
|
||||||
;;; module-eshell.el ends here
|
;;; module-eshell.el ends here
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
"A-/" 'evil-commentary-line
|
"A-/" 'evil-commentary-line
|
||||||
"M-b" 'doom:build
|
"M-b" 'doom:build
|
||||||
"C-`" 'doom/popup-last-buffer
|
"C-`" 'doom/popup-last-buffer
|
||||||
"M-~" 'doom/eshell
|
"C-~" (λ! (doom:eshell t))
|
||||||
;; Text-scaling
|
;; Text-scaling
|
||||||
"M-0" (λ! (text-scale-set 0))
|
"M-0" (λ! (text-scale-set 0))
|
||||||
"M-=" 'text-scale-increase
|
"M-=" 'text-scale-increase
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
(ex! "http" 'httpd-start) ; start http server
|
(ex! "http" 'httpd-start) ; start http server
|
||||||
(ex! "rx" 'doom:regex) ; open re-builder
|
(ex! "rx" 'doom:regex) ; open re-builder
|
||||||
(ex! "repl" 'doom:repl) ; invoke or send to repl
|
(ex! "repl" 'doom:repl) ; invoke or send to repl
|
||||||
(ex! "sh[ell]" 'doom/eshell)
|
(ex! "sh[ell]" 'doom:eshell)
|
||||||
(ex! "t[mux]" 'doom:tmux) ; send to tmux
|
(ex! "t[mux]" 'doom:tmux) ; send to tmux
|
||||||
(ex! "tcd" 'doom:tmux-cd) ; cd to default-directory in tmux
|
(ex! "tcd" 'doom:tmux-cd) ; cd to default-directory in tmux
|
||||||
(ex! "x" 'doom:scratch-buffer)
|
(ex! "x" 'doom:scratch-buffer)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue