Bash color prompt and long commands

Posted by Eric J. on Super User See other posts from Super User or by Eric J.
Published on 2010-04-12T18:58:27Z Indexed on 2010/04/12 19:03 UTC
Read the original article Hit count: 501

Filed under:
|
|
|

I'm colorizing parts of my bash prompt using ANSI escape sequences. This works great, until the command I'm currently typing in is long enough that it has to wrap. Instead of the rest of the command displaying on the next line, it wraps back to column 1 of the current line, overwriting the beginning of the prompt.

I get that behavior with this prompt:

export PS1="[\u][\033[0;32;40mdemo \033[0;33;40m1.5.40.b\033[0;37;40m] \w> \033[0m"

but it works correctly with the same prompt, ANSI sequences remove:

export PS1="[\u][demo 1.5.40.b] \w> "

I'm connecting using the current version of Putty, with default Putty settings. The OS is Ubuntu 8.10.

© Super User or respective owner

Related posts about bash

Related posts about command-prompt