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:

mperdikeas@thorin:~#
$ 

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)}\[\033[1;32m\]\u@\h\[\033[00m\]:\[\033[1;33m\]\w\[\033[00m\]#\n$'
else
  PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w#\n$ '
fi 

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
add comment

2 Answers

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
  dumb)
    PROMPT_COMMAND=
    PS1="\u@\h:\W$ "
esac
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
add comment

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

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

Your Answer

 
discard

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.