Quantcast

Forums | MacLife

You are not logged in.

#1 2006-04-01 2:01 am

cosmicosmo
Chancellor Mmmm
From: Peninsula, Ohio, US of A
Registered: 2003-02-06
Posts: 237
Website

prompt color

is there any way to have a color shell prompt?  it is very hard to find the beginning of the output of the most recent command run if there is a lot of it.  This should make it easier.  perhaps better would be an indentation of output.  Is this possible?


I hate your wimper

Offline

 

#2 2006-04-01 11:46 am

resedit
Chicken Little
Royal Wombat
From: /dev/null
Registered: 1999-11-01
Posts: 50212
Website

Re: prompt color

http://www.pantz.org/scripting/shell/colorterm.shtml

That might have what you are looking for.


It's not hard to quit smoking. I do it 20 times a day.

Offline

 

#3 2006-04-01 11:55 am

resedit
Chicken Little
Royal Wombat
From: /dev/null
Registered: 1999-11-01
Posts: 50212
Website

Re: prompt color

Try this:

Code:

export PS1="\e[35m[\u@\h \w]$\e[30m "

If that is what you want - then add that line to your ~/.bashrc

\e[35m

makes everything after it purple.
\e[30m

makes everything after it black.

So what that command does is set up the prompt to be purple, and then once the prompt is done, it resturns it to black.


It's not hard to quit smoking. I do it 20 times a day.

Offline

 

#4 2006-04-01 4:08 pm

akb825
ph34r teh master sword
From: In a secluded room
Registered: 2003-12-25
Posts: 6434
Website

Re: prompt color

w00t, thanks for that tip. Since I have my terminal window black, I used the colors 32 and 37 for green and purple. BTW, do you have any idea how to control that kind of thing when programming (such as in C)? Or is it something that you could just change an environmental variable for the current color?

Edit: nevermind, I dissected your command and noticed it had the escape character \e before the color values, and I now got it to work.

Editx2: I found this page that shows the color codes. If you just have 0 for the color code, it will return to the default. I now have this in my .profile file (.bashrc doesn't work correctly on the Mac due to the way it starts up the shells) export PS1="\e[32m[\u@\h \w]$\e[0m "

Last edited by akb825 (2006-04-01 4:19 pm)


My software

"Standards are for n00bs!!!" -Microsoft

Offline

 

#5 2006-04-01 6:40 pm

drmbb
Member
From: Charlottesville, VA
Registered: 2005-05-12
Posts: 90

Re: prompt color

I have, in my .tcshrc file (never bothered moving to bash with Tiger - way too much customization baggage to convert):

set prompt="%{\033[33;40m%}%d. %W/%D %n \n %/ -> %{\033[36;40m%} "

That gives me a yellow prompt, eg for today:

Sat. 04/01 <userid>
<path-to-current-directory> ->

My normal terminal text is light blue, and I always use a black background.


Michael:
15", 1.5GHz AlBook, 1.5GB RAM, 128MB VRAM, 80GB 5400rpm HD
work: 2x2.5GHz G5 powermac, 4GB RAM, 2x250GB HDs
OS X 10.4.8

Offline

 

#6 2006-04-01 11:07 pm

cosmicosmo
Chancellor Mmmm
From: Peninsula, Ohio, US of A
Registered: 2003-02-06
Posts: 237
Website

Re: prompt color

nifty.  that does indeed work.  I went with

PS1="\[\e[31;1m\]\t/\W$\[\e[0m\]"

You've got to have '\[' before and '\]' after each change in color or it will mess up long commands.

It seems to be helping in finding the prompt a good bit.  Thanks.


I hate your wimper

Offline

 

#7 2006-04-02 1:58 am

akb825
ph34r teh master sword
From: In a secluded room
Registered: 2003-12-25
Posts: 6434
Website

Re: prompt color

Thanks for the heads up. After a bit of tweaking, this is my final PS1 string: "\[\e[32m[\u \w]$\e[0m \]"


My software

"Standards are for n00bs!!!" -Microsoft

Offline

 

#8 2006-04-02 1:02 pm

Nefarious
Tuning Fork
Moderator
From: 45°22"N 84°57"W
Registered: 2002-09-30
Posts: 7994

Re: prompt color

akb825 wrote:

snip

So which file do we put one of these commands as a default ?  I never heard of  the profile file.

Offline

 

#9 2006-04-02 2:25 pm

akb825
ph34r teh master sword
From: In a secluded room
Registered: 2003-12-25
Posts: 6434
Website

Re: prompt color

.bashrc is the traditional place to put such commands, but Mac OS X invokes the shell by logging you in to the shell rather than initiating it the same way many other *nixes do it. So in that case, the .profile is read instead of .bashrc.

Basically, put all that stuff in .profile. tongue I don't know why it doesn't just read both, but that's just how it seems to work. shrug

BTW, I also put
alias ls='ls -G'
in there a while ago so that my ls would have color support. (and that's when it took a while for me to discover that you needed to put this stuff in .profile instead of .bashrc on Mac OS X tongue)


My software

"Standards are for n00bs!!!" -Microsoft

Offline

 

#10 2006-04-02 2:36 pm

Nefarious
Tuning Fork
Moderator
From: 45°22"N 84°57"W
Registered: 2002-09-30
Posts: 7994

Re: prompt color

Color Purple and "ls -G"  successfully added.  smile

Offline

 

#11 2006-04-02 2:54 pm

akb825
ph34r teh master sword
From: In a secluded room
Registered: 2003-12-25
Posts: 6434
Website

Re: prompt color

For added visibility, you can also add a ;5 after your color option. For example, \e[35;5m. I guarantee it will catch your eye quite well. wink


My software

"Standards are for n00bs!!!" -Microsoft

Offline

 

#12 2006-04-02 3:43 pm

Nefarious
Tuning Fork
Moderator
From: 45°22"N 84°57"W
Registered: 2002-09-30
Posts: 7994

Re: prompt color

I used resedit's

Code:

export PS1="\e[35m[\u@\h \w]$\e[30m "

Where to put your mod ?

Offline

 

#13 2006-04-02 6:30 pm

akb825
ph34r teh master sword
From: In a secluded room
Registered: 2003-12-25
Posts: 6434
Website

Re: prompt color

Nefarious Bidding wrote:

I used resedit's

Code:

export PS1="\e[35m[\u@\h \w]$\e[30m "

Where to put your mod ?

Code:

export PS1="\e[35;5m[\u@\h \w]$\e[30m "

I suggest that regardless of if you decide you like it or not (it's good for a laugh, and certainly will catch your eye, but maybe not recommended for long-term use tongue), you change the last \e[30m to \e[0m since it will then always revert to the default color. That way, if you ever decide to change your color scheme, you won't have to look up the color for what you choose. Also, if you're using some color that doesn't fit into the 8 or so listed, then you won't have to have a "best guess".

Edit: here's my suggested code with all the modifications done so far.
"Extra eye-catcher:"

Code:

export PS1="\[\e[35;5m[\u@\h \w]$\e[0m \]"

Normal:

Code:

export PS1="\[\e[35m[\u@\h \w]$\e[0m \]"

Last edited by akb825 (2006-04-02 6:31 pm)


My software

"Standards are for n00bs!!!" -Microsoft

Offline

 

#14 2006-04-02 7:36 pm

cosmicosmo
Chancellor Mmmm
From: Peninsula, Ohio, US of A
Registered: 2003-02-06
Posts: 237
Website

Re: prompt color

ha ha.  5 is quite noticable.  hopefully I won't need that much visibility.  4 (underline) can also help.  or any of the text backgrounds (the 40s).


I hate your wimper

Offline

 

#15 2006-04-03 8:19 am

Fracai
Evacipate
From: St. Elsewhere
Registered: 2000-05-25
Posts: 2832

Re: prompt color

Code:

[\[\e[37;1m\]\u\[\e[0m\]@\[\e[37m\]\h\[\e[0m\]:\[\e[34;1m\]\W\[\e[0m\]]\$

[user@machine:folder] $ in different colors


   i am jack's amusing sig file
        http://alum.wpi.edu/~arno/i/s.png
Satellite Lot :: Second Summer

Offline

 

#16 2006-04-05 6:29 pm

djdawson
Member
From: Minnesota, USA
Registered: 2001-04-19
Posts: 1860

Re: prompt color

FYI:

Code:

#
# VT100 Terminal Control Codes for Pretty Prompt Strings:
#
# Set Display Attribute Mode:      <ESC>[{attr1};...;{attrn}m
# Sets multiple display attribute settings. The following lists standard attributes:
# 0       Reset all attributes
# 1       Bright
# 2       Dim
# 4       Underscore      
# 5       Blink
# 7       Reverse
# 8       Hidden
# 
#         Foreground Colours
# 30      Black
# 31      Red
# 32      Green
# 33      Yellow
# 34      Blue
# 35      Magenta
# 36      Cyan
# 37      White
# 
#         Background Colours
# 40      Black
# 41      Red
# 42      Green
# 43      Yellow
# 44      Blue
# 45      Magenta
# 46      Cyan
# 47      White

Dana
[MA]{O}FSG

Offline

 

#17 2006-04-05 11:54 pm

cosmicosmo
Chancellor Mmmm
From: Peninsula, Ohio, US of A
Registered: 2003-02-06
Posts: 237
Website

Re: prompt color

1 comes out as bold.  reverse switches the fore and background colors


I hate your wimper

Offline

 

#18 2006-04-06 12:29 am

akb825
ph34r teh master sword
From: In a secluded room
Registered: 2003-12-25
Posts: 6434
Website

Re: prompt color

I already linked a page with the color codes. (my first post even tongue)


My software

"Standards are for n00bs!!!" -Microsoft

Offline

 

Board footer

Powered by PunBB 1.2.6
© Copyright 2002–2005 Rickard Andersson