Coder Social home page Coder Social logo

esh-autosuggest's Introduction

esh-autosuggest

https://melpa.org/packages/esh-autosuggest-badge.svg https://stable.melpa.org/packages/esh-autosuggest-badge.svg

Fish-like history autosuggestions in eshell

demo.gif

Installation

This package is on melpa. If you have melpa in your package repositories, you can use M-x RET package-install RET esh-autosuggest or install with use-package:

(use-package esh-autosuggest
  :hook (eshell-mode . esh-autosuggest-mode)
  ;; If you have use-package-hook-name-suffix set to nil, uncomment and use the
  ;; line below instead:
  ;; :hook (eshell-mode-hook . esh-autosuggest-mode)
  :ensure t)

Alternatively, consider installing with straight.el or quelpa-use-package.

Otherwise, download the files to somewhere on your load path, and require esh-autosuggest:

(require 'esh-autosuggest)

Usage

This package assumes you use something other than company for eshell completion (e.g. eshell-pcomplete, completion-at-point, helm-esh-pcomplete). company-mode is used solely as a mechanism for history autosuggestions.

Unless you’re using use-package’s hook keyword as described in Installation, you can enable the autosuggestions with:

(add-hook 'eshell-mode-hook #'esh-autosuggest-mode)

Key Bindings

  • <right> and C-f are used to select the suggestion.
  • M-<right> and M-f are used to select the next word in the suggestion.

Keys can be modified using esh-autosuggest-active-map.

If instead you don’t want company-active-map to be overridden, you may set esh-autosuggest-use-company-map to t. This may cause unexpected behavior when pressing RET or TAB, depending on what you want those to do. To emulate fish-shell most closely, it is recommended you leave this nil, as that will explicitly run your input (regardless of suggestion) on RET, and bring up your preferred completion system on TAB.

Delay

esh-autosuggest-delay defaults to 0 seconds. This is most like fish shell’s instant history autosuggestions, but can be customized.

With other backends (not recommended)

It is technically possible to group this backend with other company backends like e.g. company-capf like so:

;; don't add esh-autosuggest-mode to eshell-mode-hook
(defun setup-eshell-grouped-backends ()
  (setq-local company-backends
              '((company-capf esh-autosuggest))))

(add-hook 'eshell-mode-hook #'setup-eshell-grouped-backends)

This isn’t recommended since the history suggestions will be neither fish-like, nor will they work after typing the first word on the command line, since company-backends need to share a prefix to work together smoothly. See company-mode/company-mode#744 for more information.

Known bugs and workarounds

If you’re using evil-collection, there’s a known issue that occurs when evil-collection-company-use-tng is set to t (the default). If you don’t need that feature, you can set it to nil for the time being.

Rationale and tips

I made this package to help ease a transition from zsh to eshell as my main shell. The reason the main mechanism is a minor-mode that overrides company-mode is that I didn’t find company-mode that useful for eshell completion.

While the default popup-buffer frontend to pcomplete can be a bit annoying, I’ve found there are alternatives that make pcomplete behave more like normal shell completion. Try one or more of the following for tab completion:

  • Ambrevar/emacs-fish-completion
  • If you use helm
    (defun setup-eshell-helm-completion ()
      (define-key eshell-mode-map [remap eshell-pcomplete] 'helm-esh-pcomplete))
    
    (add-hook 'eshell-mode-hook #'setup-eshell-helm-completion)
        
  • If you use ivy
    (setq ivy-do-completion-in-region t) ; this is the default
    
    (defun setup-eshell-ivy-completion ()
      (define-key eshell-mode-map [remap eshell-pcomplete] 'completion-at-point)
      ;; only if you want to use the minibuffer for completions instead of the
      ;; in-buffer interface
      (setq-local ivy-display-functions-alist
                  (remq (assoc 'ivy-completion-in-region ivy-display-functions-alist)
                        ivy-display-functions-alist)))
    
    (add-hook 'eshell-mode-hook #'setup-eshell-ivy-completion)
        

esh-autosuggest's People

Contributors

dieggsy avatar duckwork avatar ryuslash avatar vellvisher avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

esh-autosuggest's Issues

evil-collection-init breaks esh-autosuggest

With this config esh-autosuggest will not work:


(require 'use-package)

(use-package evil
  :after general
  :init
  (setq evil-want-keybinding nil evil-want-integration t)
  :config
  (setq evil-ex-substitute-global t)
  (setq evil-undo-system 'undo-redo)
  (evil-mode 1)
  )

(use-package evil-collection
  :after evil
  :config
  (evil-collection-init))

(use-package general
  :init
  (setq evil-want-keybinding nil
	evil-want-C-d-scroll t
	evil-want-C-u-scroll t
	evil-want-integration t
	)
  :config
  (general-auto-unbind-keys) ;; NOTE not sure this works?
  (general-evil-setup t))

(use-package eshell :config)


(setq eshell-history-size 1000000)

(setq eshell-destroy-buffer-when-process-dies t)

(use-package esh-autosuggest
  :hook (eshell-mode . esh-autosuggest-mode))

(use-package company
  :config
  (setq company-minimum-prefix-length 1
        company-idle-delay 0.4
        company-selection-wrap-around t
        company-dabbrev-downcase nil
        )
  (global-company-mode))

However... if you comment out the evil-collection-init part out and call that after loading an eshell with esh-autosuggest you'll notice it changes the style of completion. Not sure why that is.

Rename to company-eshell-autosuggest

I guess this issue can be closed right away again but I was just surprised that after an update (I use borg) company-eshell-autosuggest couldn't be found anymore.

I guess all(?) company backends start with a company- prefix so to me the old name makes more sense as it describes the package better.

Doesn't work correctly with protected eshell prompts

I'm using the following snippet from Spacemacs to prevent modification of the eshell prompt:

(defun spacemacs//protect-eshell-prompt ()
  "Protect Eshell's prompt like Comint's prompts.
E.g. `evil-change-whole-line' won't wipe the prompt. This
is achieved by adding the relevant text properties."
  (let ((inhibit-field-text-motion t))
    (add-text-properties
     (point-at-bol)
     (point)
     '(rear-nonsticky t
                      inhibit-line-move-field-capture t
                      field output
                      read-only t
front-sticky (field inhibit-line-move-field-capture)))))

However, as a result of the additional text properties, (beginning-of-line) in esh-autosuggest--prefix stops right after the prompt instead of at the beginning of the prompt. This causes the while loop to fail. Perhaps we can use something like (re-search-backward "^" nil 'noerror) instead?

As a side question, can we check if (eshell-bol) returns nil and then use the result of re-search-forward? Not really sure why we need (eshell-bol) here.

Thanks!

Doesn't work correctly with multiline eshell prompts

I have a multiline prompt, however the logic in esh-autosuggest--prefix doesn't work because the lookint-at-p triggers on the first line and there eshell-bol returns nil.

Is there any reason for this logic? Woulnd't it be enough to only call eshell-bol?

Typo in Rationale and Tips section

I think the define-key form in setup-eshell-ivy-completion should read:

(define-key eshell-mode-map [remap eshell-pcomplete] 'completion-at-point)

The keymap argument is currently missing.

How can I use this together with (company-capf/pcomplete)?

I am trying to use this together with the pcomplete suggestions from emacs-fish-completion. However specifying the backend: company-eshell-autosuggest seems to only suggest the autosuggest completions. I assume you have this working looking at your setup and your blog post. If I don't have the company-eshell-autosuggest the other suggestions work very well.

I would like to have the pcomplete first and if nothing else matches fallback to this one.

Doesn't work in `eshell-command`

eshell-command reads an Eshell command from the minibuffer.

esh-autosuggest--prefix won't work in this case, since it can't find eshell-prompt-regexp in the minibuffer.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.