2019-05-18 23:41:18 -04:00
|
|
|
;;; term/eshell/config.el -*- lexical-binding: t; -*-
|
2017-02-19 18:53:38 -05:00
|
|
|
|
|
|
|
;; see:
|
2019-06-11 07:51:16 +02:00
|
|
|
;; + `+eshell/here': open eshell in the current window
|
|
|
|
;; + `+eshell/toggle': toggles an eshell popup
|
|
|
|
;; + `+eshell/frame': converts the current frame into an eshell-dedicated
|
|
|
|
;; frame. Once the last eshell process is killed, the old frame configuration
|
|
|
|
;; is restored.
|
2017-02-19 18:53:38 -05:00
|
|
|
|
2018-06-28 18:34:02 +02:00
|
|
|
(defvar +eshell-config-dir
|
|
|
|
(expand-file-name "eshell/" doom-private-dir)
|
|
|
|
"Where to store eshell configuration files, as opposed to
|
|
|
|
`eshell-directory-name', which is where Doom will store temporary/data files.")
|
2018-06-18 22:31:27 +02:00
|
|
|
|
|
|
|
(defvar +eshell-enable-new-shell-on-split t
|
|
|
|
"If non-nil, spawn a new eshell session after splitting from an eshell
|
|
|
|
buffer.")
|
|
|
|
|
|
|
|
(defvar +eshell-kill-window-on-exit nil
|
|
|
|
"If non-nil, eshell will close windows along with its eshell buffers.")
|
|
|
|
|
|
|
|
(defvar +eshell-aliases
|
|
|
|
'(("q" "exit") ; built-in
|
2018-06-30 13:20:24 +02:00
|
|
|
("f" "find-file $1")
|
2019-06-11 07:57:26 +02:00
|
|
|
("bd" "eshell-up $1")
|
2019-01-22 14:56:38 -05:00
|
|
|
("rg" "rg --color=always $*")
|
|
|
|
("ag" "ag --color=always $*")
|
2018-06-30 13:20:24 +02:00
|
|
|
("l" "ls -lh")
|
2018-06-28 18:46:51 +02:00
|
|
|
("ll" "ls -lah")
|
|
|
|
("clear" "clear-scrollback")) ; more sensible than default
|
2018-06-18 22:31:27 +02:00
|
|
|
"An alist of default eshell aliases, meant to emulate useful shell utilities,
|
|
|
|
like fasd and bd. Note that you may overwrite these in your
|
|
|
|
`eshell-aliases-file'. This is here to provide an alternative, elisp-centric way
|
|
|
|
to define your aliases.
|
|
|
|
|
2019-06-11 07:51:16 +02:00
|
|
|
You should use `set-eshell-alias!' to change this.")
|
2018-06-18 22:31:27 +02:00
|
|
|
|
2018-06-28 18:34:02 +02:00
|
|
|
;;
|
|
|
|
(defvar eshell-directory-name (concat doom-etc-dir "eshell"))
|
|
|
|
|
|
|
|
;; These files are exceptions, because they may contain configuration
|
|
|
|
(defvar eshell-aliases-file (concat +eshell-config-dir "alias"))
|
|
|
|
(defvar eshell-rc-script (concat +eshell-config-dir "profile"))
|
|
|
|
(defvar eshell-login-script (concat +eshell-config-dir "login"))
|
|
|
|
|
|
|
|
|
2018-06-18 22:31:27 +02:00
|
|
|
(defvar +eshell--default-aliases nil)
|
2018-06-14 23:36:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
2018-09-07 19:36:16 -04:00
|
|
|
;; Packages
|
2018-06-14 23:36:42 +02:00
|
|
|
|
|
|
|
(after! eshell ; built-in
|
2018-06-16 16:59:33 +02:00
|
|
|
(setq eshell-banner-message
|
|
|
|
'(format "%s %s\n"
|
|
|
|
(propertize (format " %s " (string-trim (buffer-name)))
|
|
|
|
'face 'mode-line-highlight)
|
|
|
|
(propertize (current-time-string)
|
|
|
|
'face 'font-lock-keyword-face))
|
|
|
|
eshell-scroll-to-bottom-on-input 'all
|
2017-02-19 18:53:38 -05:00
|
|
|
eshell-scroll-to-bottom-on-output 'all
|
|
|
|
eshell-buffer-shorthand t
|
2017-05-12 12:10:04 +02:00
|
|
|
eshell-kill-processes-on-exit t
|
2018-03-23 18:17:59 -04:00
|
|
|
eshell-hist-ignoredups t
|
2018-06-28 16:58:28 +02:00
|
|
|
;; don't record command in history if prefixed with whitespace
|
2019-05-29 23:44:23 -04:00
|
|
|
;; TODO Use `eshell-input-filter-initial-space' when Emacs 25 support is dropped
|
|
|
|
eshell-input-filter (lambda (input) (not (string-match-p "\\`\\s-+" input)))
|
2017-02-19 18:53:38 -05:00
|
|
|
;; em-prompt
|
2017-07-21 16:48:34 +02:00
|
|
|
eshell-prompt-regexp "^.* λ "
|
2018-06-18 22:31:27 +02:00
|
|
|
eshell-prompt-function #'+eshell-default-prompt
|
2017-02-19 18:53:38 -05:00
|
|
|
;; em-glob
|
|
|
|
eshell-glob-case-insensitive t
|
2018-03-23 18:17:59 -04:00
|
|
|
eshell-error-if-no-glob t)
|
2017-02-19 18:53:38 -05:00
|
|
|
|
2018-05-18 01:26:00 +02:00
|
|
|
;; Consider eshell buffers real
|
2019-07-18 15:27:20 +02:00
|
|
|
(add-hook 'eshell-mode-hook #'doom-mark-buffer-as-real-h)
|
2018-05-18 01:26:00 +02:00
|
|
|
|
2018-06-18 22:31:27 +02:00
|
|
|
;; Keep track of open eshell buffers
|
|
|
|
(add-hook 'eshell-mode-hook #'+eshell|init)
|
|
|
|
(add-hook 'eshell-exit-hook #'+eshell|cleanup)
|
|
|
|
|
2018-06-29 01:22:06 +02:00
|
|
|
;; Enable autopairing in eshell
|
|
|
|
(add-hook 'eshell-mode-hook #'smartparens-mode)
|
|
|
|
|
2018-07-11 00:04:24 +02:00
|
|
|
;; Persp-mode/workspaces integration
|
2019-04-21 19:59:44 -04:00
|
|
|
(when (featurep! :ui workspaces)
|
2018-07-11 00:04:24 +02:00
|
|
|
(add-hook 'persp-activated-functions #'+eshell|switch-workspace)
|
|
|
|
(add-hook 'persp-before-switch-functions #'+eshell|save-workspace))
|
|
|
|
|
2018-06-16 16:39:48 +02:00
|
|
|
;; UI enhancements
|
2018-07-01 01:19:30 +02:00
|
|
|
(defun +eshell|remove-fringes ()
|
2018-07-03 20:05:49 +02:00
|
|
|
(set-window-fringes nil 0 0)
|
|
|
|
(set-window-margins nil 1 nil))
|
2018-07-01 01:19:30 +02:00
|
|
|
(add-hook 'eshell-mode-hook #'+eshell|remove-fringes)
|
|
|
|
|
|
|
|
(defun +eshell|enable-text-wrapping ()
|
|
|
|
(visual-line-mode +1)
|
|
|
|
(set-display-table-slot standard-display-table 0 ?\ ))
|
|
|
|
(add-hook 'eshell-mode-hook #'+eshell|enable-text-wrapping)
|
|
|
|
|
2018-06-16 16:39:48 +02:00
|
|
|
(add-hook 'eshell-mode-hook #'hide-mode-line-mode)
|
|
|
|
|
2018-06-18 22:31:27 +02:00
|
|
|
;; Don't auto-write our aliases! Let us manage our own `eshell-aliases-file'
|
|
|
|
;; or configure `+eshell-aliases' via elisp.
|
|
|
|
(advice-add #'eshell-write-aliases-list :override #'ignore)
|
2018-06-16 16:38:39 +02:00
|
|
|
|
2018-06-18 22:31:27 +02:00
|
|
|
;; Visual commands require a proper terminal. Eshell can't handle that, so
|
|
|
|
;; it delegates these commands to a term buffer.
|
2017-05-12 12:07:28 +02:00
|
|
|
(after! em-term
|
2019-06-11 07:57:26 +02:00
|
|
|
(pushnew! eshell-visual-commands "tmux" "htop" "vim" "nvim" "ncmpcpp"))
|
2018-06-18 22:31:27 +02:00
|
|
|
|
|
|
|
(defun +eshell|init-aliases ()
|
|
|
|
(setq +eshell--default-aliases eshell-command-aliases-list
|
|
|
|
eshell-command-aliases-list
|
|
|
|
(append eshell-command-aliases-list
|
|
|
|
+eshell-aliases)))
|
|
|
|
(add-hook 'eshell-alias-load-hook #'+eshell|init-aliases)
|
2017-05-10 05:29:56 +02:00
|
|
|
|
2019-04-21 19:59:44 -04:00
|
|
|
(when (featurep! :editor evil +everywhere)
|
2019-06-11 07:57:26 +02:00
|
|
|
(advice-add #'evil-collection-eshell-next-prompt-on-insert :override #'+eshell*goto-prompt-on-insert))
|
2018-05-26 18:58:00 +02:00
|
|
|
|
2019-07-22 00:24:06 +02:00
|
|
|
(add-hook 'eshell-first-time-mode-hook
|
|
|
|
(defun +eshell-init-keymap-h ()
|
|
|
|
;; Keys must be bound in a hook because eshell resets its keymap every
|
|
|
|
;; time `eshell-mode' is enabled. Why? It is not for us mere mortals to
|
|
|
|
;; grasp such wisdom.
|
|
|
|
(map! :map eshell-mode-map
|
|
|
|
:n "RET" #'+eshell/goto-end-of-prompt
|
|
|
|
:n [return] #'+eshell/goto-end-of-prompt
|
|
|
|
:n "c" #'+eshell/evil-change
|
|
|
|
:n "C" #'+eshell/evil-change-line
|
|
|
|
:n "d" #'+eshell/evil-delete
|
|
|
|
:n "D" #'+eshell/evil-delete-line
|
|
|
|
:i "TAB" #'+eshell/pcomplete
|
|
|
|
:i [tab] #'+eshell/pcomplete
|
|
|
|
:i "C-d" #'+eshell/quit-or-delete-char
|
|
|
|
"C-s" #'+eshell/search-history
|
|
|
|
;; Tmux-esque prefix keybinds
|
|
|
|
"C-c s" #'+eshell/split-below
|
|
|
|
"C-c v" #'+eshell/split-right
|
|
|
|
"C-c x" #'+eshell/kill-and-close
|
|
|
|
"C-c h" #'windmove-left
|
|
|
|
"C-c j" #'windmove-down
|
|
|
|
"C-c k" #'windmove-up
|
|
|
|
"C-c l" #'windmove-right
|
|
|
|
[remap split-window-below] #'+eshell/split-below
|
|
|
|
[remap split-window-right] #'+eshell/split-right
|
|
|
|
[remap doom/backward-to-bol-or-indent] #'eshell-bol
|
|
|
|
[remap doom/backward-kill-to-bol-and-indent] #'eshell-kill-input
|
|
|
|
[remap evil-window-split] #'+eshell/split-below
|
|
|
|
[remap evil-window-vsplit] #'+eshell/split-right))))
|
2017-02-19 18:53:38 -05:00
|
|
|
|
2018-06-16 16:38:39 +02:00
|
|
|
|
|
|
|
(def-package! eshell-up
|
2019-06-11 07:57:26 +02:00
|
|
|
:commands eshell-up eshell-up-peek)
|
2018-06-16 16:51:43 +02:00
|
|
|
|
|
|
|
|
|
|
|
(def-package! shrink-path
|
|
|
|
:commands shrink-path-file)
|
2018-06-28 18:31:46 +02:00
|
|
|
|
|
|
|
|
2018-06-28 19:23:31 +02:00
|
|
|
(def-package! eshell-z
|
|
|
|
:after eshell
|
|
|
|
:config
|
2018-06-28 18:31:46 +02:00
|
|
|
;; Use zsh's db if it exists, otherwise, store it in `doom-cache-dir'
|
|
|
|
(unless (file-exists-p eshell-z-freq-dir-hash-table-file-name)
|
2018-06-28 19:23:31 +02:00
|
|
|
(setq eshell-z-freq-dir-hash-table-file-name
|
|
|
|
(expand-file-name "z" eshell-directory-name))))
|