From a9d7fc099d02257434598a6c905552860445d4c7 Mon Sep 17 00:00:00 2001 From: Steven vanZyl Date: Fri, 17 Apr 2020 15:48:54 -0400 Subject: [PATCH 1/3] Improved Eshell module part 1 Added a README file detailing the Eshell module, a few minor tweaks to the config, some keybindings, and the eshell-did-you-mean package. More to come! --- modules/term/eshell/README.org | 45 +++++++++++++++++++++++++++++++++ modules/term/eshell/config.el | 16 +++++++++++- modules/term/eshell/packages.el | 1 + 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 modules/term/eshell/README.org diff --git a/modules/term/eshell/README.org b/modules/term/eshell/README.org new file mode 100644 index 000000000..8d9f63adf --- /dev/null +++ b/modules/term/eshell/README.org @@ -0,0 +1,45 @@ +#+TITLE: term/eshell +#+DATE: April 17, 2020 +#+SINCE: {replace with next tagged release version} +#+STARTUP: inlineimages nofold + +* Table of Contents :TOC_3:noexport: + +* Description +This module provides additional features for the built-in [[https://www.gnu.org/software/emacs/manual/html_mono/eshell.html][Emacs Shell]] + +The Emacs Shell or =eshell= is a shell-like command interpreter implemented in +Emacs Lisp. It is an alternative to traditional shells such as =bash=, =zsh=, +=fish=, etc. that is built into Emacs and entirely cross-platform. + +** Maintainers +This module has no dedicated maintainers. + +** Module Flags +This module provides no flags, but does gain auto-completion if =:completion +company= is enabled. + +** Plugins ++ [[https://github.com/peterwvj/eshell-up][eshell-up]] ++ [[https://github.com/xuchunyang/eshell-z][eshell-z]] ++ [[https://github.com/tom-tan/esh-help][esh-help]] ++ [[https://gitlab.com/bennya/shrink-path.el][shrink-path]] ++ [[https://github.com/xuchunyang/eshell-did-you-mean][eshell-did-you-mean]] ++ =:completion company= + + [[https://gitlab.com/ambrevar/emacs-fish-completion][fish-completion]] + + [[https://github.com/szermatt/emacs-bash-completion][bash-completion]] + +* Prerequisites +This module has no prerequisites. + +* Features ++ Command completion with Company ++ =fish=-style prompt with Git integration ++ [[https://github.com/rupa/z][=z=]]-like directory jumping ++ Command-not-found recommendations + +* TODO Configuration +# How to configure this module, including common problems and how to address them. + +* TODO Troubleshooting +# Common issues and their solution, or places to look for help. diff --git a/modules/term/eshell/config.el b/modules/term/eshell/config.el index 412d69bdc..0b923faff 100644 --- a/modules/term/eshell/config.el +++ b/modules/term/eshell/config.el @@ -82,6 +82,10 @@ You should use `set-eshell-alias!' to change this.") ;; Enable autopairing in eshell (add-hook 'eshell-mode-hook #'smartparens-mode) + ;; Comapny completion integration + (when (featurep! :completion company) + (add-hook 'eshell-mode-hook #'company-mode)) + ;; Persp-mode/workspaces integration (when (featurep! :ui workspaces) (add-hook 'persp-activated-functions #'+eshell-switch-workspace-fn) @@ -152,7 +156,13 @@ You should use `set-eshell-alias!' to change this.") [remap doom/backward-kill-to-bol-and-indent] #'eshell-kill-input [remap evil-delete-back-to-indentation] #'eshell-kill-input [remap evil-window-split] #'+eshell/split-below - [remap evil-window-vsplit] #'+eshell/split-right)))) + [remap evil-window-vsplit] #'+eshell/split-right + + ;; Local-leader keybindings + (:localleader + "b" #'eshell-insert-buffer-name + "e" #'eshell-insert-envvar + "s" #'+eshell/search-history))))) (use-package! eshell-up @@ -183,3 +193,7 @@ You should use `set-eshell-alias!' to change this.") (defadvice! +eshell--fallback-to-bash-a (&rest _) :before-while #'fish-completion--list-completions-with-desc (executable-find "fish"))) + +;; Active eshell-did-you-mean using its setup function which provides +;; its own hooks. +(eshell-did-you-mean-setup) diff --git a/modules/term/eshell/packages.el b/modules/term/eshell/packages.el index 82a18ed14..0d287a889 100644 --- a/modules/term/eshell/packages.el +++ b/modules/term/eshell/packages.el @@ -5,6 +5,7 @@ (package! eshell-z :pin "337cb241e1") (package! shrink-path :pin "c14882c859") (package! esh-help :pin "417673ed18") +(package! eshell-did-you-mean :pin "7cb6ef") (when (featurep! :completion company) (package! fish-completion :pin "1038488181") From 85cf7a794b465ec4d0a9aa08552e81804072fb46 Mon Sep 17 00:00:00 2001 From: Steven vanZyl Date: Tue, 28 Apr 2020 09:35:06 -0400 Subject: [PATCH 2/3] Fixes from PR feedback This contains fixes suggested by Henrik as feedback from the initial PR, including updating and correcting the Eshell module README, and few tweaks to the module configuration, and properly pinning eshell-did-you-mean. --- modules/completion/company/config.el | 2 +- modules/term/eshell/README.org | 15 ++++++++++++--- modules/term/eshell/config.el | 10 +++------- modules/term/eshell/packages.el | 2 +- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/modules/completion/company/config.el b/modules/completion/company/config.el index 62a1a4f52..c44adb444 100644 --- a/modules/completion/company/config.el +++ b/modules/completion/company/config.el @@ -10,7 +10,7 @@ company-tooltip-align-annotations t company-require-match 'never company-global-modes - '(not erc-mode message-mode help-mode gud-mode eshell-mode) + '(not erc-mode message-mode help-mode gud-mode) company-backends '(company-capf) company-frontends '(company-pseudo-tooltip-frontend company-echo-metadata-frontend)) diff --git a/modules/term/eshell/README.org b/modules/term/eshell/README.org index 8d9f63adf..de43e43f8 100644 --- a/modules/term/eshell/README.org +++ b/modules/term/eshell/README.org @@ -1,9 +1,17 @@ #+TITLE: term/eshell -#+DATE: April 17, 2020 -#+SINCE: {replace with next tagged release version} +#+DATE: May 18, 2020 +#+SINCE: v2.0 #+STARTUP: inlineimages nofold * Table of Contents :TOC_3:noexport: +- [[#description][Description]] + - [[#maintainers][Maintainers]] + - [[#module-flags][Module Flags]] + - [[#plugins][Plugins]] +- [[#prerequisites][Prerequisites]] +- [[#features][Features]] +- [[#configuration][Configuration]] +- [[#troubleshooting][Troubleshooting]] * Description This module provides additional features for the built-in [[https://www.gnu.org/software/emacs/manual/html_mono/eshell.html][Emacs Shell]] @@ -30,7 +38,8 @@ company= is enabled. + [[https://github.com/szermatt/emacs-bash-completion][bash-completion]] * Prerequisites -This module has no prerequisites. +[[https://fishshell.com/][=fish= shell]] for completions, falling back to [[https://www.gnu.org/software/bash/][=bash= shell]] if =fish= is not +found. If neither shell is found, completions may not be available. * Features + Command completion with Company diff --git a/modules/term/eshell/config.el b/modules/term/eshell/config.el index 51afe2b15..d58ce2bd6 100644 --- a/modules/term/eshell/config.el +++ b/modules/term/eshell/config.el @@ -82,10 +82,6 @@ You should use `set-eshell-alias!' to change this.") ;; Enable autopairing in eshell (add-hook 'eshell-mode-hook #'smartparens-mode) - ;; Comapny completion integration - (when (featurep! :completion company) - (add-hook 'eshell-mode-hook #'company-mode)) - ;; Persp-mode/workspaces integration (when (featurep! :ui workspaces) (add-hook 'persp-activated-functions #'+eshell-switch-workspace-fn) @@ -157,8 +153,6 @@ You should use `set-eshell-alias!' to change this.") [remap evil-delete-back-to-indentation] #'eshell-kill-input [remap evil-window-split] #'+eshell/split-below [remap evil-window-vsplit] #'+eshell/split-right - - ;; Local-leader keybindings (:localleader "b" #'eshell-insert-buffer-name "e" #'eshell-insert-envvar @@ -196,4 +190,6 @@ You should use `set-eshell-alias!' to change this.") ;; Active eshell-did-you-mean using its setup function which provides ;; its own hooks. -(eshell-did-you-mean-setup) +(use-package! eshell-did-you-mean + :after eshell + :config (eshell-did-you-mean-setup)) diff --git a/modules/term/eshell/packages.el b/modules/term/eshell/packages.el index 0d287a889..1ca415927 100644 --- a/modules/term/eshell/packages.el +++ b/modules/term/eshell/packages.el @@ -5,7 +5,7 @@ (package! eshell-z :pin "337cb241e1") (package! shrink-path :pin "c14882c859") (package! esh-help :pin "417673ed18") -(package! eshell-did-you-mean :pin "7cb6ef") +(package! eshell-did-you-mean :pin "7cb6ef8e22") (when (featurep! :completion company) (package! fish-completion :pin "1038488181") From a82d93630ff140204efb5c4754c08e1f2d9de725 Mon Sep 17 00:00:00 2001 From: Steven vanZyl Date: Tue, 28 Apr 2020 16:54:34 -0400 Subject: [PATCH 3/3] Fix DYM and add aliases Fixed the use-package! declaration for eshell-did-you-mean since it needed a different mode in the :after than I thought. I also put together a quick hack to try and fix an issue with did-you-mean, but it doesn't seem to work reliably right now. More testing required. Also added two aliases, one `gg` for to open magit-status and one `ff` as an additional alias to find-file that follows the Doom keybindings better. --- modules/term/eshell/README.org | 7 +++++++ modules/term/eshell/config.el | 24 ++++++++++++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/modules/term/eshell/README.org b/modules/term/eshell/README.org index de43e43f8..ad3c5878b 100644 --- a/modules/term/eshell/README.org +++ b/modules/term/eshell/README.org @@ -8,6 +8,7 @@ - [[#maintainers][Maintainers]] - [[#module-flags][Module Flags]] - [[#plugins][Plugins]] + - [[#hacks][Hacks]] - [[#prerequisites][Prerequisites]] - [[#features][Features]] - [[#configuration][Configuration]] @@ -37,6 +38,12 @@ company= is enabled. + [[https://gitlab.com/ambrevar/emacs-fish-completion][fish-completion]] + [[https://github.com/szermatt/emacs-bash-completion][bash-completion]] +** Hacks ++ Even with =fish-completion-fallback-on-bash-p= non-nil, fish must be installed + for bash completion to work. Workaround in =config.el=. ++ =eshell-did-you-mean= does not work on first invocation, so we manually invoke + it once. + * Prerequisites [[https://fishshell.com/][=fish= shell]] for completions, falling back to [[https://www.gnu.org/software/bash/][=bash= shell]] if =fish= is not found. If neither shell is found, completions may not be available. diff --git a/modules/term/eshell/config.el b/modules/term/eshell/config.el index d58ce2bd6..b84b9016c 100644 --- a/modules/term/eshell/config.el +++ b/modules/term/eshell/config.el @@ -12,6 +12,10 @@ "Where to store eshell configuration files, as opposed to `eshell-directory-name', which is where Doom will store temporary/data files.") +(defvar eshell-directory-name (concat doom-etc-dir "eshell") + "Where to store temporary/data files, as opposed to `eshell-config-dir', +which is where Doom will store eshell configuration files.") + (defvar +eshell-enable-new-shell-on-split t "If non-nil, spawn a new eshell session after splitting from an eshell buffer.") @@ -22,11 +26,13 @@ buffer.") (defvar +eshell-aliases '(("q" "exit") ; built-in ("f" "find-file $1") + ("ff" "find-file $1") ("d" "dired $1") ("bd" "eshell-up $1") ("rg" "rg --color=always $*") ("l" "ls -lh $*") ("ll" "ls -lah $*") + ("gg" "magit-status") ("clear" "clear-scrollback")) ; more sensible than default "An alist of default eshell aliases, meant to emulate useful shell utilities, like fasd and bd. Note that you may overwrite these in your @@ -35,15 +41,11 @@ to define your aliases. You should use `set-eshell-alias!' to change this.") -;; -(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 "aliases")) (defvar eshell-rc-script (concat +eshell-config-dir "profile")) (defvar eshell-login-script (concat +eshell-config-dir "login")) - (defvar +eshell--default-aliases nil) @@ -188,8 +190,14 @@ You should use `set-eshell-alias!' to change this.") :before-while #'fish-completion--list-completions-with-desc (executable-find "fish"))) -;; Active eshell-did-you-mean using its setup function which provides -;; its own hooks. + +;; Activate eshell-did-you-mean using its setup function (lazily) (use-package! eshell-did-you-mean - :after eshell - :config (eshell-did-you-mean-setup)) + :after esh-mode ; Specifically esh-mode, not eshell + :config + (eshell-did-you-mean-setup) + ;; HACK There is a known issue with `eshell-did-you-mean' where it does not + ;; work on first invocation, so we invoke it once manually by setting + ;; the last command and then calling the output filter. + (setq eshell-last-command-name "catt") + (eshell-did-you-mean-output-filter "catt: command not found"))