Cygwin bash prompt is wrapping lines on the same line

I'm using Cygwin bash prompt, and for long commands the text will wrap around on the same line as opposed to going to the next line despite setting my PS1 to simply ' $'.

Here's a screenshot,
screenshot


Solution 1:

I was already using MinTTY, and removing the newline in PS1 didn't help either. One piece of advice on this page did help. I executed this bash command:

kill -WINCH $$

In my case, running this once fixed the issue, even after logging out and back in. I'm not sure if this is always the case.

Solution 2:

For me, the solution was to add the following lines to .bashrc:

PS1='\[\e[32m\]\u@\h:\W> \[\e[0m\]'
TERM=cygwin
export PS1
export TERM

Note that non-printable characters in the prompt must be enclosed in \[ ... \].

Solution 3:

I had the same problem with MinTTY as well. The problem probably has something to do with the primary prompt (PS1).

The solution for me was removing the last 'new line' character from PS1 (right before the '$' sign):

user@host ~
$ echo $PS1
\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$

user@host ~
$ export PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\$ '

user@host ~ $

see http://cygwin.com/ml/cygwin/2001-07/msg00140.html for reference.

To make this change persistent, add export PS1='[\e]0;\w\a]\n[\e[32m]\u@\h [\e[33m]\w[\e[0m]\$ ' to your ~/.bashrc file.

Solution 4:

As commented by dregad and ak2, setting export TERM=cygwin in my ~/.bashrc file was enough to fix this problem for me.

Solution 5:

@jtpereyda's answer is certainly on the mark. But for some reason I couldn't let this go, and dug a little deeper.

Expanding on this comment, if you resize the terminal while in vim (or any other full screen application that takes control of the tty away from the shell), the resulting SIGWINCH is often not sent to the shell, so when it gets back control it doesn't know that the terminal has been resized.

When you resize your terminal it should call an ioctl(..., TIOCSWINSZ, ...) on the master pty that vim is running in. This in turn results in a killpg(SIGWINCH) on vim's process group.

The problem is that vim runs in its own process group distinct from the shell it was exec'd from, so the bash shell does not receive the SIGWINCH and does not adjust its lines/columns appropriately.

If you want a permanent workaround, add shopt -s checkwinsize to your .bashrc. That makes bash check the window size (ioctl(..., TIOCGWINSZ, ..)) after returning from each command, and update its lines/columns.