I was getting a little tired of my typeaheads in Bash from messing up the PS1. For instance, I would execute a command, like
ls, and while it is running, start typing the next command, like
echo, and the typeahead for
echo would appear before the PS1, like
/$ls ... ec/$echo
/$ is the
PS1). My solution for this was to add
\r to the front of the PS1, so that it would clear the line first.
This seems to work reasonably well, but there seems to be a strange issue. In my
.inputrc, I have
to let me type
M-p to go backward (iTerm 2 maps Option to escape correctly).
The issue is that sometimes when I type some stuff and then
M-p to get the previous command, then I do a
C-u C-k to clear the line, the first character stays, and becomes part of the
PS1 (it is deleted from the executed line, but it is shown on the PS1). It does away when I execute the command, but whenever I hit that item in the history, even with the regular up arrow, that first character gets stuck there again. This only seems to happen with commands that are of a certain length. It doesn't matter if the
\r actually clears any text for it to happen.
Am I hitting a strange bug in bash and/or iTerm? Is adding
\r to the front of
PS1 the correct way to clear cruft before it?