My term in emacs appear:

0;me@debian: ~me@debian:~$

instead of me@debian:~$

~$ echo $PS1
\[\e]0;\u@\h: \w\a\]\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;33m\]\w\[\033[00m\]\[\033[0;35m\]$\[\033[0m\]


debian-9.5.0 and GNU Emacs 25.1.1

I tried various solutions given in stackexchange by adding additional lines to .bashrc and init.el

But nothing worked out. This issue is there in shell also; but not in eshell.

  • Show us what you tried. What were these "various solutions" which didn't work? Also, what does echo $PS1 report in the shell? Does the problem persist if you type export PS1="\u@\h:\w$ " at the shell prompt?
    – phils
    Commented Sep 16, 2018 at 1:05
  • Phils: Thanks for response. I edited the question.
    – A. John
    Commented Sep 16, 2018 at 2:32
  • Phils: I tried your advice: (1) No syntax highlight or bold text (2) And it last for that terminal session only.
    – A. John
    Commented Sep 16, 2018 at 2:44
  • Actually, I think you might be seeing exactly what your PS1 says to display. At minimum, you have \u@\h in there twice. Why is that?
    – phils
    Commented Sep 16, 2018 at 2:46
  • Reducing that to just PS1="\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;33m\]\w\[\033[00m\]\[\033[0;35m\]$\[\033[0m\] " (eliminating the duplicate at the start) seems to work in both term and my stand-alone terminal (at least in cursory tests).
    – phils
    Commented Sep 16, 2018 at 2:53

2 Answers 2


Based on the S.O. duplicates linked to in the question, the initial \[\e]0;\u@\h: \w\a\] is intended to set the title text of an xterm window. If the terminal does not recognise those (non-standard) escape codes (as is the case in term and shell), you end up with the situation shown in the question.

If you want to retain the xterm behaviour in compatible terminals, you should perform the appropriate tests in your shell config when setting PS1, such that you only set that prefix in situations where it is supported.

If you don't care about xterm window titles, then just remove the prefix from the prompt entirely. If you want to keep those, then add those codes conditionally.

# Generic colour prompt (works in Emacs)
PS1="\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;33m\]\w\[\033[00m\]\[\033[0;35m\]$\[\033[0m\] "

# In an xterm, also set the window title
case $TERM in
    xterm*) PS1="\[\e]0;\u@\h: \w\a\]$PS1";;
  • Perfect answer. Phils, thank you for your time, effort, and sincere approach. Hats off to you !!!
    – A. John
    Commented Sep 16, 2018 at 21:43
  • Is there a way to get the terminal title also back? In fact, i did not notice that it was missing...
    – A. John
    Commented Sep 16, 2018 at 22:05
  • I can only suggest the general approach described in stackoverflow.com/a/17598138 whereby you would conditionally set PS1 to have those additional escape sequences only if the value of TERM matched xterm*. You don't need to define a function, though -- I would just put the case block directly in your config file (and of course substitute your own title and prompt for the ones they've used).
    – phils
    Commented Sep 16, 2018 at 22:20
  • n.b. If that doesn't do the trick, you may have some other terminal which also supports those escape codes, and hence might need to test for additional TERM patterns. If it's all a mystery, let me know what echo $TERM says.
    – phils
    Commented Sep 16, 2018 at 22:33
  • xterm-256color My Xfce terminal and eshell works perfectly fine.
    – A. John
    Commented Sep 17, 2018 at 0:07

I ran into this and found it was caused (in fish at least), by fish_title being set.

This resolved the issue:

if status is-interactive
    if [ "$TERM" = "eterm-color" ]
        # pass
        function fish_title
            if [ $_ = 'fish' ]
                echo "["(prompt_pwd)"]"
                echo "("$_")"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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