emacs: what's eshell? eshell vs shell

Perm url with updates: http://xahlee.org/emacs/eshell.html

Emacs: What's eshell? “eshell” vs “shell” Difference?

Xah Lee, 2010-10-09, 2011-01

I've always thought that eshell was just a toy, and never really tried to use it other than knowning it's written entirely in elisp. But over the past few years i learned from emacs community, that apparently many people do use it. Also, because eshell is written in emacs lisp, that means you can enter elisp code or call any of the 3000+ elisp commands or functions directly in the eshell command line.

For example, try typing “(+ 3 4)” in the prompt, and it returns “7”.

What's eshell? how's it different from shell?

eshell is written entirely in elisp.

Practically speaking, that means when you are on Windows and don't have Cygwin installed, you can still use all the common unix ls, cd, mkdir, cp, grep, ... stuff, in eshell.

How to set environment variable FOR eshell?

you can get and set environment variables for emacs use only by:

; show env var named path
(getenv "PATH")

; example of setting env var named “path”
; by prepending new paths to existing paths
(setenv "PATH"
   "C:/cygwin/usr/local/bin" ";"
   "C:/cygwin/usr/bin" ";"
   "C:/cygwin/bin" ";"
   (getenv "PATH") ; inherited from OS

Put in your emacs init file. Restart emacs, or, select the code then call “eval-region”.

This will effect environment variable within emacs only. It won't change the real environment variables used by OS.

When you call a command such as “perl” that's not in eshell, eshell will try to find it in the env var PATH. Also, emacs do inherit your PATH environment variable from OS. For detail, see: Emacs and Microsoft Windows Tips.

Advantages of Eshell Over a Regular Shell

NikkiA at reddit gave some very useful tips:

  • Platform agnostic - it works the same on unix based OSes and Windows
  • tramp integration - if you start an eshell while default-directory is pointing at a buffer that is served over tramp, then eshell will use the same connection, and allow manipulation of the remote filesystem without using dired.
  • find-file ... It's just so much easier being able to type 'find-file blah' as a command it open blah in an emacs buffer (even over tramp, see above)
  • consistancy - eshell uses its own method of colouring the output of ls and thus is consistant across platforms and shell configurations, which can be important if you ever have to use it on accounts that you don't have authority to modify .bashrc/.profile on.
  • /dev/clip and /dev/kill - you can redirect shell commands to the emacs clipboard and killring
  • redirect to buffers - along with the above, you can also do things like ls >> #<buffer *scratch*> to output the result from ls to the scratch buffer

Here's a more in-depth tutorial about eshell. Mastering Eshell by Mickey @ Source www.masteringemacs.org

Eshell is written by John Wiegley. Thanks John.

Popular posts from this blog

Browser User Agent Strings 2012

11 Years of Writing About Emacs

does md5 creates more randomness?