Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make eshell tab completion behave like Bash

Tags:

emacs

eshell

How can I make eshell autocomplete behave like Bash and Emacs in general i.e. it offers a list of choices rather than arbitrary selects one for you?

For example, if I have two directories "Download" and "Downloads", when I type "Down" and hit TAB, I expect another buffer pops up and shows me the choices. But eshell just completes it for me, i.e. if I press TAB, it completes to "Download"; hit TAB again, it changes to "Downloads".

like image 274
Amumu Avatar asked Nov 07 '13 08:11

Amumu


People also ask

How does Tab autocomplete work?

Using autocomplete is as simple as pressing the [TAB] and the active command line options will fill-in. If more than one option is available, you can hit [TAB] twice to display all possible choices and continue typing until there is only one matching choice left.

How do I know if bash completion is installed?

Depending on your package manager, you have to manually source this file in your ~/. bashrc file. Reload your shell and verify that bash-completion is correctly installed by typing type _init_completion .

What is tab completion in Linux?

Command-line completion (also tab completion) is a common feature of command-line interpreters, in which the program automatically fills in partially typed commands.


2 Answers

You only need to have the following line:

(setq eshell-cmpl-cycle-completions nil)

eshell-mode automatically set pcomplete-cycle-completions to the value of eshell-cmpl-cycle-completions locally.

like image 167
xuhdev Avatar answered Sep 28 '22 17:09

xuhdev


(add-hook
 'eshell-mode-hook
 (lambda ()
   (setq pcomplete-cycle-completions nil)))

and

(setq eshell-cmpl-cycle-completions nil)

Both do as you ask and show a buffer listing the completions when I run my emacs as 'emacs -q' to avoid my own customizations. This is with emacs 23.3, are you running a much older version?

Also see http://www.emacswiki.org/emacs/EshellCompletion which is where I first went to check this out.

Steps to try this out:

  1. Start emacs using 'emacs -q' as the command -- no other arguments.
  2. Change to the *scratch* buffer
  3. Paste or type in one of the above code snippets
  4. Put your cursor at the end of the snippet and press 'C-e' to execute the code.
  5. Start eshell
  6. test
  7. if neither one works, report back here with your version info and any other relevant details
like image 24
Sean Perry Avatar answered Sep 28 '22 16:09

Sean Perry