Shell prompt is repeated when using ssh in ansi-term

When I use SSH to log in to Ubuntu 12.04 from an ansi-term session in emacs, the prompt is not displayed correctly:

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

It should look like this:

 ubuntu@jumplin :~$ 

I tried several suggestions regarding utf-8 and color support, but they don't seem to work (color currently works fine in ansi-term):

Strange characters in ansi-term in emacs

I think this may be due to an unsupported ansi exit code or something similar, but I'm not sure what the PS1 value for this terminal session is:

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

Any advice would be greatly appreciated :) I always seem a little lost when strange characters appear on terminal sessions.

+4
source share
3 answers

\[\e]0;\ u@ \h: \w\a\] at your invitation, you need to configure the xterm (?) header line. Although ANSI coloring is supported by ansi-term , the escape sequences that control the header are not. This is why you see repetition twice - the first section should go to the title bar.

So, either delete the first sequence from your PS1, or do something similar to what is offered in the Bash HOWTO request :

 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 if you are in ansi-term , TERM will be equal to eterm-color .

+4
source

Thanks to the answer from Alex Vorbiev, I solved this when ssh'ing on an Ubuntu 14.04 environment with bash, from my Emacs 24.5 on MacOSX, just commenting on a similar section in my .bashrc on the guest machine.

Same:

 # 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 

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

I use Emacs term or multi-term packages, and echo $TERM returns xterm-256color

0
source

I don't know if this will work for ansi-term , but I had the same problem with eshell and I fixed it with this alias

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

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

0
source

Source: https://habr.com/ru/post/1490786/


All Articles