Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

When I am using the emacs M-x shell mode I see strange characters on my screen which I believe are related to my prompt (which includes an End-Of-Line) and the use of colors.

So, here's what I see on the terminal:


And here's what I see inside Emacs shell buffer:

^[]0;mperdikeas@thorin: ~^Gmperdikeas@thorin:~#

Here's the relative section of my .bashrc:

if [ "$color_prompt" = yes ]; then
  PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w#\n$ '

How can I configure emacs to properly display the prompt in the shell buffer?

share|improve this question
Have you tried M-x terminal-emulator? –  jordanm Jan 19 '13 at 17:49
the display is even worse than when using M-x shell –  Marcus Junius Brutus Jan 19 '13 at 20:34
You are right, the garbage is leftovers of ESC sequences for setting colors and such. –  vonbrand Jan 21 '13 at 17:47

2 Answers 2

up vote 5 down vote accepted

There's probably a more elegant solution, but this works for me. After any prompt-related lines in .bashrc, insert the following, adjusting the value of PS1 to suit:

# Keep it simple if running in emacs.
case "$TERM" in
    PS1="\u@\h:\W$ "
share|improve this answer
Yeap, that did the trick (replacing dumb with xterm-256color which was my setting). –  Marcus Junius Brutus Jan 19 '13 at 20:40

I think you'd better enable ansi-color in your shell-mode settings.

 (eval-after-load 'shell
      (autoload 'ansi-color-for-comint-mode-on "ansi-color" nil t)
      (add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on t)
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.