Colour PS1 prompt behaviour..

3 views
Skip to first unread message

Cillian Sharkey

unread,
Aug 10, 1999, 10:00:00 AM8/10/99
to
Hi,

When trying to "colourise" my bash prompt by inserting some colour
codes (eg: \033[01;32m etc..) into the PS1 variable, weird things
started happening.

Basically, when you started to type in long commands or try and
backspace those long commands, the screen would be screwed up in various
ways depending on what terminal you were using.

I've tried this on a linux console, linux telnet session, freebsd
console and freebsd xterm all with differing behaviour, the bash
version on linux was: 1.14.7(1) and on freebsd it was 2.02

Is it possible to have a colour PS1 prompt without
any adverse side effects?

Thanks in advance,
- Cillian

Chet Ramey

unread,
Aug 10, 1999, 10:00:00 AM8/10/99
to
> When trying to "colourise" my bash prompt by inserting some colour
> codes (eg: \033[01;32m etc..) into the PS1 variable, weird things
> started happening.

Read the Bash FAQ, question E3.

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
( ``Discere est Dolere'' -- chet)

Chet Ramey, Case Western Reserve University Internet: ch...@po.CWRU.Edu

Paul D. Smith

unread,
Aug 10, 1999, 10:00:00 AM8/10/99
to
%% cil...@baker.ie (Cillian Sharkey) writes:

cs> When trying to "colourise" my bash prompt by inserting some colour
cs> codes (eg: \033[01;32m etc..) into the PS1 variable, weird things
cs> started happening.

cs> Basically, when you started to type in long commands or try and
cs> backspace those long commands, the screen would be screwed up in
cs> various ways depending on what terminal you were using.

Check the FAQ.

(Hint: question E5).

--
-------------------------------------------------------------------------------
Paul D. Smith <psm...@baynetworks.com> Network Management Development
"Please remain calm...I may be mad, but I am a professional." --Mad Scientist
-------------------------------------------------------------------------------
These are my opinions---Nortel Networks takes no responsibility for them.

Paul D. Smith

unread,
Aug 10, 1999, 10:00:00 AM8/10/99
to
%% ch...@nike.ins.cwru.edu (Chet Ramey) writes:

>> When trying to "colourise" my bash prompt by inserting some colour

>> codes (eg: \033[01;32m etc..) into the PS1 variable, weird things

>> started happening.

cr> Read the Bash FAQ, question E3.

E3?

Chet Ramey

unread,
Aug 10, 1999, 10:00:00 AM8/10/99
to
> %% ch...@nike.ins.cwru.edu (Chet Ramey) writes:
>
> >> When trying to "colourise" my bash prompt by inserting some colour
> >> codes (eg: \033[01;32m etc..) into the PS1 variable, weird things
> >> started happening.
>
> cr> Read the Bash FAQ, question E3.
>
> E3?

It's E3 in the latest version I sent out to the mailing list. I have to
see why my automatic update for ftp://ftp.cwru.edu/pub/bash/FAQ isn't
working.

Paul D. Smith

unread,
Aug 10, 1999, 10:00:00 AM8/10/99
to
%% Chet Ramey <ch...@nike.ins.cwru.edu> writes:

cr> Read the Bash FAQ, question E3.

>> E3?

cr> It's E3 in the latest version I sent out to the mailing list. I
cr> have to see why my automatic update for
cr> ftp://ftp.cwru.edu/pub/bash/FAQ isn't working.

It's also still E5 in the FAQ included in bash-2.03/doc, FWIW.

Do...@gorean.org

unread,
Aug 10, 1999, 10:00:00 AM8/10/99
to
Chet Ramey <ch...@nike.ins.cwru.edu> wrote:
>> When trying to "colourise" my bash prompt by inserting some colour
>> codes (eg: \033[01;32m etc..) into the PS1 variable, weird things
>> started happening.

> Read the Bash FAQ, question E3.

Before I forget, I've been posting the latest version of the FAQ on
my web site since I can never get into the FTP site.
http://home.san.rr.com/freebsd/Bash-FAQ.txt

Second, even with the ANSI codes properly (I believe) escaped, I still
have line wrapping problems. Here is my prompt:

\[\e]1;${PROMPT_HOSTNAME}\a\e]2;${PROMPT_HOSTNAME}:${PWD}\a\
\e[${PROMPT_COLOR}\][\u@${PROMPT_HOSTNAME} \w]\n \#\$ \[\e[m\]

The first set of escape sequences are xterm codes. Then I set the prompt
color, end the first \[\] pair, set the literal string for the prompt,
and then the ANSI escape codes for unsetting all attributes so that my
typed text will appear with the default color and background. With this
prompt all is well until I resize the window. Then the first character I type
sends the cursor back to the last position on the previous line, or sometimes
to the first posistion on the current line (which is actually 3 characters
plus the number of characters for the history entry too far left).

I have the checkwinsize shopt enabled, although that doesn't help
with this problem. I also have the horizontal-scroll-mode enabled in my
.inputrc, although the behavior is the same with and without this option.
Also, putting the prompt string all on one line has no effect.

I'll be glad to help test any patches, etc. designed to fix this
problem, but over the years I've kind of gotten used to it, and I hardly
ever look at the screen to see the commands I type anymore anyway. :)

HTH,

Doug
--
On account of being a democracy and run by the people, we are the only
nation in the world that has to keep a government four years, no matter
what it does.
-- Will Rogers

Reply all
Reply to author
Forward
0 new messages