If I do this:
echo foo PS1='\e[0;30mtest \e[0m'
and then presses the up arrow test PS1='\e[0;30mtest \e[0m' appears (as expected).
But if I press up arrow, so I should have echo foo, it results in test PS1='\e[0;3echo foo
If I set the PS1 to anything which doesn’t include color it works:
echo foo
PS1='\e[0;30mtest \e[0m'
PS1='test '
- triple press up arrow, results in
echo foo
Note: echo foo is still the command executed if I press Enter
I have tried this in both iTerm2 and the apple Terminal.
Why is it doing that and how do I fix it?
Try this:
By using extra
\[and\]brackets, you are tellingbashthat you’ve got some non-printing characters, which it may be misinterpreting when you press the up-arrow.