In shell buffers inside Emacs (M-x shell), many programs want to use color in useful ways. For example, grep can highlight the portion of the line that matches the search pattern. Here's what I use to make Emacs and XEmacs show colors in shell windows:

;;; Shell mode
(setq ansi-color-names-vector ; better contrast colors
      ["black" "red4" "green4" "yellow4"
       "blue3" "magenta4" "cyan4" "white"])
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)

I also use these settings to turn off word wrap and to make the prompt read-only:

(add-hook 'shell-mode-hook 
     '(lambda () (toggle-truncate-lines 1)))
(setq comint-prompt-read-only t)

Shell mode is handy but I find that I often just switch to a terminal window, mainly because I can pipe commands through less. If the output is very short, either Emacs or a terminal is fine. If it's of medium length, Emacs is usually nicer, since it lets me search and cut and paste easily. If the command has very long output, the terminal is nicer, because less lets me see just parts of the output. I haven't found a way in Emacs to deal with processes that output lots of lines.



Alok wrote at Wednesday, April 25, 2007 at 6:18:00 AM PDT

That is curious. I don't use the Emacs shell. But looks like obviously entering a command which can read keyboard input or dump terminal code output does not work well with emacs.

Matt wrote at Tuesday, May 1, 2007 at 7:42:00 AM PDT

Why not just use use M-x term (or M-x ansi-term) instead?

Amit wrote at Tuesday, May 1, 2007 at 8:40:00 AM PDT

Matt, the main reason I haven't used M-x term is that I learned about it after I formed my habits. I should try it though and see if it's worth changing my habits. :-)

Matt wrote at Tuesday, May 1, 2007 at 12:08:00 PM PDT

Ah, I wasn't aware ansi-term is not available in XEmacs.

Arky wrote at Wednesday, February 11, 2009 at 7:12:00 AM PST

I think I like M-x ansi-term better. I use it on Emacs-Gtk most of the time

Justin wrote at Tuesday, July 12, 2011 at 7:47:00 AM PDT

Thanks! Works great!

Anonymous wrote at Wednesday, August 1, 2012 at 4:35:00 PM PDT

Emacs shell is my IDE for almost everything. It's very very powerful and convenient. I have multiple shells open, renamed to something nice. And I can cut and past between them, save output as "log" files, instantly create shell scripts. Better than bash for sure.
Start using that shell and continue.
For special cases, use "ansi-term" which provides a nice display, with lots less flexibility (handles "man ls" for example).

Anonymous wrote at Monday, August 26, 2019 at 7:12:00 AM PDT

I don't suppose anybody's got colors working for shell on emacs 27?