bash history buffer output mangled after repeated up-arrow

Garance A Drosehn drosih at rpi.edu
Thu Apr 26 01:10:42 UTC 2018


On 25 Apr 2018, at 10:26, tech-lists at zyxst.net wrote:

> hi,
>
> I've noticed now, for a while (like maybe over a year) that if you're in
> bash shell, hitting up-arrow (which usually loads history -1) multiple
> times will result in part of history becoming the prompt.

When I've seen this, it has been because:

1)  bash thought the width of the current window had a different
    number of columns than it actually has.
  or
2)  the variable $PS1 is set to some custom value, and that value
    includes some characters use up either more or less than one
    column-width.

In my case, case #2 happens when I'm playing games to set specific
colors in my prompt.  So, for instance, my PS1 includes the string
'\e[1;34;47m' which sets the color of both the background and the
text.  However, all those characters will use up zero columns when
displayed.  Bash needs to know that all those characters use up
zero columns, so those characters need to be surrounded by '\['
and '\]'.  Thus the string really needs to be:  '\[\e[1;34;47m\]'

I think there are some other 'tty' settings which can also cause
the behavior that you're seeing, but I don't remember which ones.

-- 
Garance Alistair Drosehn                =     drosih at rpi.edu
Senior Systems Programmer               or   gad at FreeBSD.org
Rensselaer Polytechnic Institute;             Troy, NY;  USA


More information about the freebsd-questions mailing list