5

When I use SSH to login to a Ubuntu 12.04 machine from an ansi-term session in emacs the prompt displays incorrectly:

0;ubuntu@jumplin: ~ubuntu@jumplin:~$

This should look like the following:

ubuntu@jumplin:~$

I've tried a few of the suggestions in relation to utf-8 and colour support however they don't seem to be working (colour currently works fine in ansi-term):

Strange characters in ansi-term in emacs

I think it might have something to do with a unsupported ansi escape code or something like that, but I'm not really sure - the value of PS1 for this terminal session is:

\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$

Any advice would be much appreciated :) I always seem to get a bit lost when strange characters show up in terminal sessions.

Community
  • 1
  • 1
Jordan Hagan
  • 161
  • 1
  • 7

3 Answers3

4

\[\e]0;\u@\h: \w\a\] in your prompt is to configure your xterm(?)'s title bar. Even though ANSI colorization is supported by ansi-term, the escape sequences that manipulate title bar are not. That is why you see the prompt repeated twice - the first section is supposed to go to the title bar.

So either remove the first sequence from your PS1 or do something similar to what is suggested in Bash Prompt HOWTO:

function proml
{
case $TERM in
    xterm*)
        local TITLEBAR='\[\033]0;\u@\h:\w\007\]'
        ;;
    *)
        local TITLEBAR=''
        ;;
esac

PS1="${TITLEBAR}\
[\$(date +%H%M)]\
[\u@\h:\w]\
\$ "
PS2='> '
PS4='+ '
}

You can test specifically if you are in ansi-term, the TERM will be equal to eterm-color.

Alex Vorobiev
  • 4,349
  • 21
  • 29
  • Thanks for the great answer - that makes a lot of sense. This problem only shows up on systems that I `ssh` into - there are a lot of these so changing the prompt on all of them is probably not going to happen. Do you know of any client side fixes by any chance? You've given me enough information to continue digging now though so I'll accept your answer as well =) – Jordan Hagan Jul 11 '13 at 19:47
  • You can probably use ssh to append the relevant snippet to your remote .bashrc or .bash_profile prior to starting an interactive ssh session. – Alex Vorobiev Jul 12 '13 at 03:07
  • @JordanHagan have you manage to solve this? it also happens to me when I am ssh-ed into a system. – Ciprian Tomoiagă Dec 09 '13 at 22:46
  • In the conditional statement I would not check for the contents of `TERM` but for the contents of `INSIDE_EMACS`, as I have described in this answer: http://stackoverflow.com/questions/24812345/emacs-terminal-bash-ps1-prompt-duplicated/39496135#39496135 – Christian Herenz Sep 14 '16 at 18:27
0

Thanks to Alex Vorbiev's answer above I solved this when ssh'ing into a Ubuntu 14.04 environment running bash, from my Emacs 24.5 on MacOSX by simply commenting out the similar section in my .bashrc on the guest machine.

Like so:

# If this is an xterm set the title to user@host:dir
# case "$TERM" in
# xterm*|rxvt*)
#     PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
#     ;;
# *)
#     ;;
# esac

I then ran source ~/.bashrc and the prompt was not doubled up.

I am using Emacs' term or multi-term packages and echo $TERM returns xterm-256color

Community
  • 1
  • 1
m__
  • 101
  • 3
0

I dont know if this will work for ansi-term, but I had same issue with eshell, and i fixed it with this alias

alias ssh 'ssh $1 -t "export TERM='dumb';bash -l"'

This will make sure the PROMPT_COMMAND variable is not set on the ssh'd machine. Also with this alias there is no need to change .bashrc on every machine

Sethu
  • 323
  • 1
  • 3
  • 7