PS1 problem, cmd is looping

1

I've set PS1 to the following value:

PS1="\033[0;37m[\033[1;33m\w\033[0;37m]\n\t \[[34m\]\u\033[0;37m@\[[34m\]\[[1m\]\h\[(B[m\] $"

The problem is that any command spanning more than a line loops around and don't generate a new line. So I overwrite the line that I already have typed. What is wrong with the PS1?

Runar

Posted 2011-07-17T10:29:09.300

Reputation: 55

that's not even a valid command, bash waiting for more input – None – 2011-07-17T10:59:27.310

Answers

6

Non-printing characters in the prompt need to be surrounded by \[ and \] so that bash can properly track the length of the prompt and accommodate lines that go beyond the edge of the terminal.

Ignacio Vazquez-Abrams

Posted 2011-07-17T10:29:09.300

Reputation: 100 516

SO I should add before and after which parts of the line? – Runar – 2011-07-17T20:52:34.263

You add it before and after the parts that don't print, as many times as required. – Ignacio Vazquez-Abrams – 2011-07-17T20:53:04.523

But the line do print, but when i type in a long command it loops. – Runar – 2011-07-17T20:54:59.910

CHARACTERS. Try again. – Ignacio Vazquez-Abrams – 2011-07-17T20:55:31.403

Thanks a lot! It works now :) PS1="\033[0;37m[\033[1;33m\[\w\]\033[0;37m]\[\n\]\[\t\] \[${tRandColor}\]\[\u\]\033[0;37m@\[${tRandColor}\]\[${tBold}\]\[\h\]\[${tReset}\] \$ – Runar – 2011-07-18T05:57:01.877