kill -WINCH $$ to fix bash prompt wrapping to the same line

By Caroline Liu

Sometimes, my bash prompt wraps long lines incorrectly, such that I’m typing over my own prompt like this:

My bash prompt is wrapping long lines onto itself! The horror!

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.) To fix it:

  1. Run echo $PS1 to see what your prompt is.

  2. Make adjustments and test drive your updated prompt by executing:

    export $PS1='your_new_prompt_here'
  3. Save the version that makes you proud to be a shell user by putting the following in your ~/.bash_profile:

    export $PS1='your_amazing_new_prompt_here'

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!

Fetching comments...