Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Advantages and disadvantages between zsh and emacs' (e)shell

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.

like image 915
mt3 Avatar asked Oct 12 '10 17:10

mt3


2 Answers

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.

like image 116
Eric Warmenhoven Avatar answered Sep 24 '22 14:09

Eric Warmenhoven


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...

like image 7
SamB Avatar answered Sep 23 '22 14:09

SamB