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 commands {ls, cd, mkdir, cp, grep, …}, 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" (concat "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.
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)
- consistency - eshell uses its own method of colouring the output of ls and thus is consistent 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 @ www.masteringemacs.org…
Eshell is written by John Wiegley. Thank you John.
ls > #<buffer ttt>
output shell command to a buffer.
once you did that, you can switch to buffer easily especially if you use iswitchb-buffer. (you should, if not already. Just call iswitchb-mode to turn it on. Then the key 【Ctrl+x b】 does the switch.)
though, this to me seems still too much to type #<buffer ttt>. If the output is not pages long, easier to simply copy & paste.
thanks to Gregory Collins.
eshell is great. But because it's a complete new shell, it has learning pains, as well as some quirks. Here's some collection of problems, some are due to me not understanding eshell.
eshell doesn't have any documentation.
in shell, i can run this to convert all gif to png:
find . -name "*gif" | xargs -l -i basename "{}" ".gif" | xargs -l -i convert "{}.gif" "{}.png"
but in eshell, i get this error:
convert: unable to open image `.gif': No such file or directory. convert: missing an image filename `.png'. convert: unable to open image `.gif': No such file or directory. convert: missing an image filename `.png'.
why doesn't this work in eshell?
lynx -dump -display_charset=utf-8 -width=90 http://xahlee.org/ > x.html
i get:
Spawning child process: invalid argument
Solution: on Windows, it needs to be lynx.exe. Else, eshell gets confused.
in emacs eshell, why the following doesn't work?
find . -name "*bmp"
~/web/xahlee_org/math/i/bejeweled $ find . -name "*bmp" /usr/bin/find: paths must precede expression: x183313.bmp Usage: /usr/bin/find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
Andrew Hyatt: Try echoing to make sure that eshell is doing what you think. Or `set-trace' the call-process call to see what exactly is getting run.
, it works now. No idea why.