31

I use Ubuntu8.10 and emacs-snapshot. Running shell-mode on emacs and input "ls" shows escape codes:

screenshot http://lh3.ggpht.com/_os_zrveP8Ns/SdMmohKNjmI/AAAAAAAADB4/VlKpr5H_7ZA/s512/screen.png

How can I get the output I expect?

Luke Girvin
  • 13,221
  • 9
  • 64
  • 84
linjunhalida
  • 4,538
  • 6
  • 44
  • 64
  • Well, those funny characters are escape sequences ('ESC' '[' '0' 'm') which can serve a s a clue to others, but I won't answer since I don't know a specific fix. – paxdiablo Apr 01 '09 at 08:46

6 Answers6

44

You can use AnsiTerm which does support colors or you can enable AnsiColor for the normal shell:

(autoload 'ansi-color-for-comint-mode-on "ansi-color" nil t)
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
danielpoe
  • 3,756
  • 23
  • 18
  • 1
    Note that in order for this to have any effect, `ansi-color-process-output` must be in `comint-output-filter-functions`. – updogliu Apr 27 '14 at 04:26
5

Furthermore, you may choose another shell: M-x term or M-x eshell. The former provides an interface that is much closer to a real terminal emulator than shell-mode (once you start it, you can get out of the mode with C-c C-j and get in again with C-c C-k). The latter is a shell implementation written in Elisp (you can use the common shell commands as well as evaluating Lisp code).

viam0Zah
  • 25,949
  • 8
  • 77
  • 100
  • I know eshell, but I don't like it, not that powerful. – linjunhalida Apr 01 '09 at 09:49
  • 1
    You are saying a general purpose programing langauge is less powerful than *shell*? I think you just don't know how to use it. – jrockway Apr 02 '09 at 00:36
  • I do not mean that. It is not about any languages versus shell, but the `shell-mode` and its alternatives. If you want a shell inside Emacs, I found myself `term-mode` much convenient, which allows the buffer to behave like a real terminal or you can work on it as any other common Emacs buffer. – viam0Zah Apr 06 '09 at 10:48
3

Expanding on vatine's answer, you can add that inside your .cshrc (.tcshrc/.bashrc) wrapped with a check for the environment variable INSIDE_EMACS.

For example (from my .tcshrc):

if ( $?INSIDE_EMACS ) then
   alias l 'ls --color=never'
endif
Community
  • 1
  • 1
Trey Jackson
  • 73,529
  • 11
  • 197
  • 229
  • For `sh` and compatibles, `test "$INSIDE_EMACS" && alias l='ls --color=never'` though you might want to use a function instead of an alias. – tripleee Aug 04 '15 at 20:49
2

M-x ansi-color-for-comint-mode-on

1

I wrapped my alias ls ='ls --color=auto' in ~/.bashrc:

case "$TERM" in
xterm*|rxvt*)
    if [ -x /usr/bin/dircolors ]; then
        alias ls='ls --color=auto'
        ...
    fi
    ;;
*)
    ;;
esac

This disables using color=auto in emacs.

steabert
  • 6,540
  • 2
  • 26
  • 32
1

The problem is that "l" is trying to colorise the output and emacs isn't having any of it. Try the following:

$ unalias l
$ alias l ls --color=never
Vatine
  • 20,782
  • 4
  • 54
  • 70