Custom prompt botched during history and control-a in OS X's Terminal.app using Bash

I customized my prompt in .bash_profile to look like this:

export PS1="\w \e[0;32m\$(vcprompt -f '[%n:%b]')\e[m\$ "

Now, when I press up arrow to go back through history, find the one I want, then press control-a to go to the beginning of the line, it often stops me at the 5th character instead of going all the way to the beginning. Those first few characters are then "frozen" in place. If I arrow up or down from there it's as if those characters are the new $.

I press return and am back to normal, but it's quite irritating to have those characters stuck there! Did I screw something up in the customization? Thank you!


Solution 1:

You need to mark the nonprinting sections of the prompt with \[ ... \] so bash can tell they won't take up space on screen. Try:

export PS1="\w \[\e[0;32m\]\$(vcprompt -f '[%n:%b]')\[\e[m\]\$ "