[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[SOLVED] bash prompt won't wrap properly



On 2007-04-16, Tyler Smith <tyler.smith@mail.mcgill.ca> wrote:
> On 2007-04-15, Gerard Robin <g.robin3@free.fr> wrote:
>
>> I encountered the same problem and I solved it adding \]\n[\ in my PS1.
>>
>> my PS1:
>>
>> PS1="${magenta}[\[$TIME\] \[$LOAD\]]\[${NC}\]\n[\u@\h
>> \[${BLUE}\]\#\[$NC\]]\w\$ "
>>
>> hth.
>
>
> That's interesting. If I put the \n at the end of my prompt it works
> right. If I put it at the beginning or in the middle I get the same
> problem - the first line wraps at 66 characters, and overwrites the
> line rather than spilling onto the next line. I've discovered that the
> second and presumably all subsequent lines wrap correctly at 80
> characters and spill onto the following line, rather than overwriting
> the current line.
>

Ok, I found a website that explained what I was doing wrong:

http://www-128.ibm.com/developerworks/linux/library/l-tip-prompt/

It wasn't the addition of the battery time output from acpi, it was
the addition of some escaped colour codes that weren't properly nested
in \[ \]. My defective prompt was (split onto two lines for clarity):

'\033[01;31m\]$(bt)\033[00m\]|\033[01;32m\]\u\[\033[00m\]:
				
\[\033[01;34m\]\W\[\033[00m\]-> '

My corrected prompt is:

'\[\033[01;31m\]$(bt)\[\033[00m\]|\[\033[01;32m\]\u\[\033[00m\]:
 ^^                  ^^           ^^		

\[\033[01;34m\]\W\[\033[00m\]-> '


Maybe that will save someone some trouble in the future.

Cheers,

Tyler



Reply to: