Help on controlling BASH command line

Lennart Sorensen lsorense-1wCw9BSqJbv44Nm34jS7GywD8/FfD2ys at public.gmane.org
Sun Jun 5 14:47:18 UTC 2005


On Sat, Jun 04, 2005 at 11:42:48AM -0400, pking123-rieW9WUcm8FFJ04o6PK0Fg at public.gmane.org wrote:
> Hello
> 
> I have noticed over the past 10 years a "feature" about BASH (or 
> probably xterm) that has me mildly annoyed. It is only now that I 
> wish to discuss it since no one I know of has complained about it.
> 
> I like coloured command prompts. My current one is:
>              PS1='\e[1;31m\h\e[m::\e[1;33m\w\e[m \e[1;32m>\e[m'
> Now if I type in a command, say of more than 20 characters, the 
> display goes nuts. That is, the cursor jumps to the previous line on 
> some nonrandom column and continues for another 5 or 6 characters, 
> then jumps to the previous line to that.
> 
> This could be a problem with xterm, although trying it now on a 
> console, there is an earliy linebreak to the line below, so the 
> program running the command line just deals with the bug differently.
> 
> Now, if I type a line, I would like it to be *me* that inserts the 
> carriage returns; not the program. Is there a way to do this?

Bash is not aware of escape codes so it just sees a prompt consisting of
some 40 or 50 characters, and assumes that is how many characters wide
the prompt is.  So when the prompt length and the amount typed reaches
the width of the display, it wants to wrap and continue on another line.
So either you have to figure a way to tell bash the real length of the
prompt or use a shell that does know about escape codes.  I think zsh
might, but I am not sure.  I do have something similar to yours above in
my zsh setup and it wraps at the right location every time.  I guess
that means zsh does do the right thing.

Lennart Sorensen
--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list