From WikEmacs
Revision as of 06:03, 11 March 2014 by Elvince (talk | contribs) (eshell)
Jump to: navigation, search

Eshell is an entire shell by John Wiegley written in Emacs Lisp.

Work in progress manual: Eshell - the emacs shell

Category Eshell -Emacs Wiki-

Eshell: mastering Eshell

There are several shells for Emacs, but none can match the versatility and integration with Emacs like Eshell. Eshell is a shell written entirely in Emacs-Lisp, and it replicates most of the features and commands from GNU CoreUtils and the Bourne-like shells. So by re-writing common commands like ls and cp in Emacs-Lisp, Eshell will function identically on any environment Emacs itself runs on.


Unlike the other shells in Emacs, Eshell does not inherit from comint-mode, the default mode for interacting with inferior processes in Emacs. But because Eshell is not an inferior process, it does not have to use comint; but while that may seem like a good thing, it does mean that hooks and routines written for comint-mode won’t work with Eshell.

However, almost all the Emacs commands common to comint-mode are reimplemented natively in Eshell — and most share the same keybinds — but there are a few new advances that haven’t been ported over to Eshell, like the spiffy comint-history-isearch-backward-regexp in Emacs 23.2, bound to M-r.

Eshell works well on any platform Emacs itself runs on, as Eshell interacts with a common middleware (namely the Emacs-Lisp/C source library) and that middleware will in turn communicate with your OS on how to go about copying files and what have you. That middleware support enables Eshell to take advantage of TRAMP as well.

Given Emacs’ UNIX origin, Eshell emulates traditional UNIX shells like bash and the GNU toolchain. This is good news if you are using Windows and cannot be bothered fidgeting with cygwin, or if you require a completely portable Emacs with few or no external dependencies.

And actually, the Windows support in Eshell is a lot better, in many ways, than cygwin’s bash. You do not have the /cygdrive/c crud to contend with, as Eshell natively supports Windows/MS-DOS drive paths (so cd D: and D: both work equally well.)

Despite all the advantages offered by Eshell, there are some points I want to make that seem to confuse some people:

  • Eshell is not a terminal emulator. It does not talk to a shell, for it is the shell. Everything it does — from displaying stuff on the screen, to fetching the contents of a directory — it does through Emacs, and Emacs in turn talks to your operating system.
  • Because of the way Eshell talks to other processes (asynchronous ones especially) there may be issues with the way it buffers text and how interrupts work.
  • Eshell does not support interactive (or “visual” in Eshell parlance) programs, like top, directly; you must tell Eshell to launch them in a separate ansi-term instance instead.
  • It is not bash or zsh or even csh; do not treat it as such, even though it is heavily inspired by them. To use Eshell effectively you should treat it as if you are using a completely alien shell.


Eshell is capable of invoking almost any elisp function loaded in Emacs. That sort of flexibility is unmatched; there are no shells out there capable of approximating what Eshell can do. In fact, this functionality is heavily used (and encouraged!) by Eshell. If you want to open the file foobar.txt in Emacs you simply invoke
find-file foobar.txt
and Eshell will map that to the elisp call (
find-file "foobar.txt"
) and open the file for you.

Technical Details

All commands evaluated by Eshell have an evaluation order, which is an ordered list your command must pass through to determine what part of Eshell handles it. If there is nothing on the list that wants to evaluate your command, you will be told your command is invalid.

Assuming you want to execute the command cp, the evaluation order is:

  • A full filepath (e.g. /bin/cp) runs cp in /bin
  • Look for the command prefix,
    (default is *), and if it is found then look for the command in the search path.
  • Look for a shell-defined alias (alias command)
  • Look for cp in the search path, $PATH (or
  • Look for a Lisp function named cp or the elisp function eshell/cp
The variable
makes internal elisp calls take priority over external calls. What that means is when it’s set to t Eshell will look for an elisp function first, instead of last. If the command prefix is specified, though, this directive is ignored.