Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

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
up vote 0 down vote accepted

Further building on DaveEmme's answer here's what I finally put in my .bashrc to keep things simple:

case "$EMACS" in
    PS1="[\u@\h:\w]$ "

Relying on the value of $TERM didn't work in my case whereas Emacs is required to set the $EMACS environment variable to true for any shells it spawns.

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.