20

The symptom of the problem looks like "[0m[27m[24m[J[34;1" which on a terminal translates into the color blue.

-A

Luke Girvin
  • 13,221
  • 9
  • 64
  • 84
Setjmp
  • 27,279
  • 27
  • 74
  • 92

4 Answers4

31

I've got the following in my .emacs

(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
Chris Conway
  • 55,321
  • 43
  • 129
  • 155
  • The autoload is not necessary in recent version of Emacs (it's autoloaded by default). – cjm Nov 03 '08 at 00:16
  • 1
    This did help, (color blue appeared) however some ASCII control codes still appeared in the buffer. No doubt there are one or more details to combine with this solution. – Setjmp Nov 05 '08 at 03:02
  • I think that this answer is getting upvotes reflects that it is working on some common platforms for stackoverflow users. But see also the accepted answer. – Setjmp Jul 08 '11 at 16:25
  • Works for me in bash, so far anyway. – nroose May 28 '13 at 21:10
2

The solution that is currently giving me some success is to redefine the shell function as an ansi term:

;; shell-mode
(defun sh ()
  (interactive)
  (ansi-term "/bin/zsh"))
Setjmp
  • 27,279
  • 27
  • 74
  • 92
  • 1
    This is a good idea. It also solves the incompatibility of shell-mode with commands like more/less and man. – Chris Conway Nov 06 '08 at 02:37
  • 3
    Shadows the "real" shell command. Use term or ansi-term directly instead of hiding the plain shell mode. – remvee Dec 09 '09 at 11:09
1

For the "ignore" alternative, put something like "alias ls=ls" or "unset LS_COLORS" in your ~/.emacs_{bash,tsch,whatever-your-shell-is-called} file. This file is executed in all subordinate shells created by emacs.

Emacs sends the new shell the contents of the file ~/.emacs_shellname as input, if it exists, where shellname is the name of the file that the shell was loaded from. For example, if you use bash, the file sent to it is ~/.emacs_bash. If this file is not found, Emacs tries to fallback on ~/.emacs.d/init_shellname.sh.

Alex Coventry
  • 68,681
  • 4
  • 36
  • 40
0

The following should work in your .bash_profile or .bashrc

case $TERM in
xterm-color)
export PS1='\[\e]0;\W\007\]\[\e[34;1m\]\W\[\e[0m\]\$ '
;;
*)
export PS1='\W\$ '
;;
esac
cefstat
  • 2,336
  • 1
  • 18
  • 25