Sometimes, my bash prompt wraps long lines incorrectly, such that I’m typing over my own prompt like this:
I used to just live with it, trying to remember what I already typed and counting characters if I was going back to change something. That made my Unix experience much more frustrating that it should’ve been, because executing this single command immediately resolved the issue:
kill -WINCH $$
What does this do? You’re basically telling bash that the window size has changed. It turns out that if you resize your terminal window, bash sometimes doesn’t notice the size change without you giving it an extra nudge. Without the correct window size in hand, bash can’t wrap your text correctly!
If that doesn’t solve your bash wrapping woes, then it may be because your prompt format is incorrect. (Yup, I’ve been there, done that.) Do
echo $PS1 to see what your prompt is, make changes and test drive your updated prompt by doing
export $PS1='your_new_prompt_here', and save the version that makes you proud to be a shell user by putting
export $PS1='your_amazing_new_prompt_here' in your
~/.bash_profile. Arabesque has a detailed guide on formatting your prompt, and Fabien Loison has way too much info about adding colour to your prompt.
Have fun at the command line!