Why does this bash prompt sometimes keep part of previous commands when scrolling history

bashprompt

My bash prompt, which I'll admit to have stolen from a few places and cobbled together, will sometimes add part of previous commands to its length when scrolling the bash history with up/down arrows.

For example, if my previous commands were:

ls
cd /home/caleb
vim .bashrc

When I was at my prompt and scrolled up twice it might look like:

$ vim .bcd /home/caleb

Where the first five characters are left over from last command.

Does anyone have any idea why this is happening, and how it can be stopped?

My prompt is set with this code (way to long to include here): https://gist.github.com/1679352

Best Answer

Somewhere your prompt is fubar. What usually happens is that your shell thinks its outputting non-printable term codes and expecting it to take up space. The best advice I can give you is to systematically add to (or take away from) your prompt until this behavior stops to isolate the code that is causing this issue.