2

When a path is too long to fit on the terminal and it wraps, the following prompt is broken and you can't see properly what is typed. See screenshot below:

enter image description here

These are the contents of .bashrc that set the PS1, which is the default provided by Ubuntu.

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# 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

The value of $PS1 is

echo "$PS1"
\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ 

Is there any way to fix it?

I have seen several other similar questions, and the proposed solution is to enclose the offending part in \[ \], or to set checkwinsize, but neither worked in my case.

If anyone wants to test with the path, it is the folowing:

/home/dimitriv/Dropbox/personal/kastoria/2018-2019/προγραμματισμός στο διαδίκτυο/newslides
user000001
  • 3,347
  • 19
  • 30
  • 1
    Not a fix, of course, but I would strongly suggest you avoid using both spaces and non-ASCII characters in path names whenever possible. Just to make your life easier. And I speak from experience, I face the same issues you do (Έλληνας και εγώ). – terdon Nov 05 '18 at 10:54

1 Answers1

3

A quick fix could be to replace the window title setting part of PS1 with a PROMPT_COMMAND script.

Inside the case "$TERM" in ... esac block from your .bashrc, replace the PS1=... with

PROMPT_COMMAND='printf %b "\e]0;${debian_chroot:+($debian_chroot)}$USER@$HOSTNAME:$PWD\a"'
  • This seems to be working. But I can't say I understand the reason. Can you explain why using `PROMPT_COMMAND` instead of `PS1` helps in this situation? – user000001 Nov 04 '18 at 14:56
  • 1
    It's just a bug in bash -- it's fixed in the latest [sources](http://git.savannah.gnu.org/cgit/bash.git). I'll try to dig out the exact patch that fixed it -- it's probably [this](http://git.savannah.gnu.org/cgit/bash.git/commit/?id=b0776d8c49ab4310fa056ce1033985996c5b9807). –  Nov 04 '18 at 15:04