Introduction to Emacs Shell
While starting up a new job, I’ve been pretty pre-occupied and have
neglected my weekly learning more about the tools I use everyday.
However, I was this morning, I was re-impressed with how well Emacs’
eshell-mode works with Zshell, and thought I’d explain a bit more
After you’ve started Emacs, just hit
M-x and type
eshell and you’ll
start up what appears like a shell process in an Emacs buffer. Most of
the keystrokes you expect from a shell and from Emacs are available,
with a few exceptions:
C-nmove the cursor up instead of replaying the history. Use the up and down arrow keys or
M-nto get the history.
C-ctwice in order to break out things.
!!history works just as you expect.
- Typing the name of an executable runs it, and colors are accepted, so
lsworks as you expect.
- If the command you type isn’t a program available to the shell, it
assumes that it is an Emacs command, so instead of typing
find-fileto load the file up in an Emacs buffer.
- Tab completion is done by Eshell, and isn’t as powerful as Zshell. Does anyone know how we can call Zshell for that feature? Seems like a difficult problem.
Keep in mind that it isn’t an actual Z shell. Type
echo $0 to prove
that nothing is actually running. Eshell just looks like a shell. When
you type in a command, it then spawns off your current shell for
Since Eshell doesn’t have an actual shell executable hanging around, it is a bit more efficient, however, this is why your hot cool Zshell prompt doesn’t display, nor are your aliases available.
I know, I know. I have a lot of functions and aliases that I depend on,
however, you can add something like the following to
.emacs file to
get back some of what you’ve lost:
(defalias 'e 'find-file)
However, this becomes a global command, not just what is available in Eshell. To localize it, use this instead:
(defun eshell/e (file) (find-file file)) (defun eshell/ee (file) (find-file-other-window file))
Definitely create a
eshell/emacs command just in case you make a
More on Aliases
You can have more traditional aliases if you drop the equals sign, as in:
alias ll 'ls -l $*'
Note: Unlike a normal shell alias, the arguments aren’t automatically
appended, so you need to place the
The aliases that you define in this way are automatically saved. Restart
Emacs and an Eshell, and type
alias and you’ll see all your aliases.
Want to dive in a bit deeper?