Advantages and disadvantages between zsh and emacs' (e)shell
Asked Answered
J

3

35

i have currently switched over to emacs (aquamacs) and am in the process of migrating my entire workflow into it one step at a time (org-mode, dired, etc., from pathfinder, notational velocity, etc.).

the one thing i have yet to try (and seems to be the biggest obstacle thus far) is the built-in emacs shell (shell and/or eshell, here on referred to as "eshell"), due to having zsh setup perfectly for me. unsure if there is a way to essentially mirror/minimize the conversion/adaptation steps required.....

my questions:

  1. can eshell be treated as a superset of zsh (i.e., eshell can do everything that zsh can, plus more)? i assume eshell lacks quite a bit compared to standard shells (bash, zsh, ksh, tcsh, etc.), otherwise it would be one of the standard shells (correct me if i'm wrong to think about it that way).

  2. what are the main limitations in using eshell over zsh? any folks switch from zsh to eshell and feel there are aspects of zsh you critically miss?

  3. anyone know of any links/resources doing a zsh/eshell feature comparison?

  4. further, any resources on making the change from one's usual shell to eshell? advice on workflow migration?

  5. if eshell isn't as "powerful" as zsh, then what advantage does eshell have over zsh? any tips and tricks on using eshell within emacs that would illustrate the time spent learning it?

  6. should one just give up on eshell and continue using zsh if it does everything i think i need? or are the few "power workflows" worth it (of which i'm not aware of)?

thnx in advance.

Johnsonian answered 12/10, 2010 at 17:51 Comment(0)
U
43

Regarding M-x eshell:

  1. Eshell is not a stand-alone shell; it's implemented in pure elisp, so can't be run outside emacs, which is why it's not one of the standard shells. It doesn't have its own scripting language like bash/zsh/etc. have; it has elisp, and some command interpretation stuff to make calling elisp a little cleaner.

  2. I can't speak to zsh vs eshell, but I've mostly switched from bash to eshell. 95% of the time, eshell does everything I want or need without any problems. I don't use it for ssh. Also, you can't background a process once it's started (but you can start it backgrounded).

  3. It's going to be really hard, because zsh has a full scripting language, whereas eshell is basically an interface to the elisp interpreter. What are you looking for in an interactive shell? Eshell can probably do most of it. Conditional statements and loops on the command line? Sure. Aliases, functions, wildcards, programmable completion? Sure.

  4. The way I migrated was to basically start from scratch. Every time I ran into something that I didn't like or I wished it did, I'd figure out how to get it to do what I want. For example, eshell uses pcomplete.el for programmable completion, so adding completion functions is pretty easy.

  5. Integration with emacs is the big win for me. You can have elisp functions piped to shell commands. For a silly example, try:

    message "hello world" | cut -f 1 -d ' '
    Some commands (notably grep) get put in emacs buffers, so e.g. you can quickly jump to the results.
  6. Depends on how much time you really spend in emacs. If you do everything in emacs, it's useful, because sometimes it's easier to pipe together elisp commands with other commands through eshell. If you don't find yourself copy&pasting between emacs and your shell too frequently, it's probably not going to be a win, and you're going to have to spend time customizing it to the point you're comfortable with it.

As an alternative to eshell, M-x shell runs your normal shell underneath which interprets all the commands (so doesn't have access to elisp functions), while command-line editing (and therefore programmable completion, history, etc.) is done by emacs. I use it for ssh.

One other alternative is M-x term, which is a terminal emulator inside emacs, and usually runs a shell underneath, and the shell does all of its normal things. Then there's absolutely no conversion/adaptation steps required.

Unkindly answered 12/10, 2010 at 20:20 Comment(3)
eric, since yours is the only reply, by default you win "best answer". thnx 4 the info.Johnsonian
I don't understand the line about "...because zsh has a full scripting language, whereas eshell is basically an interface to the elisp interpreter..." Sorry, but elisp isn't a full scripting language?Dipnoan
This is a really good writeup. 'basically only a lisp interpreter interface' should be more than enough for you to do anything you want, since you have elisp at your hands, tough. :)Renfrew
R
7

Different Syntax

Since eshell allows mixing elisp code in with shell commands, it has some rather unusual syntax, which you'll need to be careful of.

One thing to watch out for is the syntax for command expansion: zsh uses the syntax

file $(which foo)

but in eshell this means basicaly the same thing as

file (which foo)

which means to run the file command on the result of evaluating the elisp expression (which foo), which typically results in an error like this:

Symbol's function definition is void: which

It turns out that the way to write this in eshell is actually

file ${which foo}

Portability

Since eshell is written in platform-neutral Emacs Lisp code, it works in essentially the same way on Windows-native Emacsen as it does on *nix, right out of the box (though of course you'll probably want coreutils and suchlike); getting shell-mode to work with a *nix shell there is presumably at least somewhat trickier.

I think I have seen some wonkiness with completion of absolute paths, though, because of the colon after the drive letter, but that's not exactly a show-stopper...

Rum answered 19/3, 2011 at 21:47 Comment(0)
D
0

I think all your 6 questions can be translated to just one question: All things can be done in zsh that can be done in Emacs? The answer is YES and there are more. I'd not say shell, eshell or other some Emacs' mode yet I just say Emacs.

shell, eshell just Emacs's mode, if I can find a way or mode at least in which can do anything that zsh can do, so it answers your question. The way is ansi-term mode in Emacs, it can run zsh inside Emacs perfectly, if you can't do your job in shell or eshell you can switch to ansi-term mode in Emacs, so your question has gone.

eshell just elisped shell and those is not good at interactive/scrolling commands such as top, less, etc.

Deimos answered 27/8, 2015 at 15:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.