emacs terminal bash (PS1) prompt duplicated
The error comes from the export PROMPT_COMMAND=...
statement.
You can avoid this being read in your configuration, by checking whether you have a shell running inside emacs or not. Here the environment variable INSIDE_EMACS
becomes handy. From the Emacs manual (Sect. 32.7):
Emacs sets the environment variable INSIDE_EMACS in the subshell to ‘version,comint’, where version is the Emacs version (e.g., ‘24.1’). Programs can check this variable to determine whether they are running inside an Emacs subshell
In your example, you wantexport PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*} $(eval "echo ${MYPSDIR}")\007"
only being executed when you are not in emacs, otherwise you get this nasty "double prompt". The following conditional statement in your code will help.
if [ -z "$INSIDE_EMACS" ]; then export PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*} $(eval "echo ${MYPSDIR}")\007"' else export PROMPT_COMMAND=''fi
It checks whether you are not inside emacs, and only then the PROMPT_COMMAND
variable is set to your desired value.
The extra display is coming from the PROMPT_COMMAND
variable's contents. emacs appears not to understand the OSC 0 title setting xterm escape sequence and so prints out the output.