Mac – How to fix the prompt in emacs shell-mode

bashemacsprompt

I'm doing some programming on a colleague's machine. He has a version of emacs (23.1.1) I haven't used before. My problem is that when I go to shell-mode, my bash prompt looks like this:

^[]0;jay@socrates:~^G[jay@socrates]$ 

I have PS1 set to '[\u@\h]\$ ' in my .bashrc. It's supposed to look like this:

[jay@socrates]$

This is how it looks in a regular shell. I've also checked that PS1 is set to the correct value in the emacs shell, so now I'm out of ideas. How can I get my prompt to look the way I want?

I've seen some suggestions to use term or eshell instead of shell. term has the same prompt problem as above, and eshell completely ignores my PS1 so that doesn't really help.

Best Answer

Your shell is trying to set the XTerm's (or other console) title/header. There are a number of ways this might be being done.

First make sure the PS1 is really what you think it is

echo $PS1 | less -E

That will tell you if there are control characters in the prompt, less will make them look funny. Assuming your prompt is exactly as you say, then it is probably the PROMPT_COMMAND environment variable. You can look at that the same way...

echo $PROMPT_COMMAND | less -E

If the prompt command is the problem, then you can just unset it. In either case, these variables are being set up somewhere, and should not be set to update the XTerm header, if you're not in an XTerm!

You can look in the "standard" bashrc (/etc/bashrc). You should see code that checks for an iteractive shell (is PS1 set), and then checks for xterm (looking at $TERM variable), and does something different there than for other terminal types.

I suspect somewhere in the bash initialization is a hard-coded setup, which should only be done on xterm-compatible console programs. Read man bash to find a total list of files you can look for and through.

If all of the above fails, try

printenv | less

And see if you can find something suspicious in there, and then track down where it is being set. Post it here if you can't work it out.

Related Question