Shell prompt repeating when using ssh in ansi-term

若如初见. 提交于 2019-11-30 21:04:17

\[\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.

m__

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

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!