Help on controlling BASH command line
John Wildberger
wildberger-iRg7kjdsKiH3fQ9qLvQP4Q at public.gmane.org
Mon Jun 6 17:19:48 UTC 2005
On Sunday 05 June 2005 10:47 am, Lennart Sorensen wrote:
> 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,
It appears to me that Bash is not confused by escape codes.
Here are some sample bash lines (Mandrake 10):
1 john [~]$ echo $PS1
2 \u [\w]\$
3 john [~]$
4 john [~]$ PS1="\n\e[43;1m[\h]\e[m [\u]:\e[42;1m \@ \e[m \e[44;1m [\w]
5 \e[m\n\\$"
6
7 [localhost] [john]: 01:02 PM [~]
8 $ here you can type a command that exceeds the display field over several
lines.
line 4 changes the prompt from the original (line 3) to a deliberate complex
structure to give color control. The line wraps correctly over to line 5
without giving any problems. The four items in the new prompt are color
controlled. The hostname is in read, the user name is in neutral, the time is
in green and the current path is in blue. There is a newline at the beginning
and a newline at the end to permit a full line for command usage.. The \\$ at
the very end ensures that the $prompt changes to a # when used with 'su'.
John
--
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