Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jmxp69

macrumors 6502
Original poster
Dec 10, 2008
324
0
I finally decided to spend a little time tweaking terminal, and I thought I'd share some of what I came up with.

1) Display files in color:

- man ls will show you all of this, but I'll summarize
- Use the G option with ls. I put an alias for ls in my ~/.profile that looks like this:
Code:
alias dir='ls -lGhF'

l = Long Format
G = Colorize output
h = human readable file sizes
F = Displays various characters after certain file types such as a / after directories.

2) To modify the default colors for files, add to your ~/.profile:
Code:
LSCOLORS='exfxcxdxbxegedabagacad' ; export LSCOLORS
** This is the default Mac Terminal Color Set

Change ex fx cx dx bx eg ed ab ag ac ad as follows:
* The first byte is the foreground color, the second byte is the background color.

ex = 1. Directory: blue/default
fx = 2. Symbolic Link: magenta/default
cx = 3. Socket: green/default
dx = 4. Pipe: brown/default
bx = 5. Executable: red/default
eg = 6. Block Special: blue/cyan
ed = 7. Character Special: blue/brown
ab = 8. Executable with setuid: black/red
ag = 9. Executable with setgid: black/cyan
ac = 10. Directory o+w with S bit: black/green
ad = 11. Directory o+w w/o S bit: black/brown

The color designators are as follows:

a black
b red
c green
d brown
e blue
f magenta
g cyan
h light grey
A bold black, usually shows up as dark grey
B bold red
C bold green
D bold brown, usually shows up as yellow
E bold blue
F bold magenta
G bold cyan
H bold light grey; looks like bright white
x default foreground or background

3) Customize your bash prompt:

This is normally a tricky endeavor due to escape sequences and syntax, so I've made it a little easier with some variables in .profile I found the titlebar and user color here. I just added the rest of the colors so you can select what you want, and expanded on his basic prompt a bit. The following goes in ~/.profile of course.
Code:
ENDCOLOR="\[\e[0m\]"
BLACK="\[\e[0;30m\]"
BLUE="\[\e[0;34m\]"
GREEN="\[\e[0;32m\]"
CYAN="\[\e[0;36m\]"
RED="\[\e[0;31m\]"
PURPLE="\[\e[0;35m\]"
BROWN="\[\e[0;33m\]"
GREY="\[\e[0;37m\]"
DGREY="\[\e[1;30m\]"
YELLOW="\[\e[1;33m\]"
WHITE="\[\e[1;37m\]"

B_BLUE="\[\e[1;34m\]"
B_GREEN="\[\e[1;32m\]"
B_CYAN="\[\e[1;36m\]"
B_RED="\[\e[1;31m\]"
B_PURPLE="\[\e[1;35m\]"

case $(id -u) in
    0)
#	   STARTCOLOR='\[\e[31m\]';
	   STARTCOLOR=$B_RED;
        ;;
    *)
#           STARTCOLOR='\[\e[36m\]';
            STARTCOLOR=$B_GREEN;
        ;;
esac



case $TERM in
    xterm*)
	TITLEBAR='\[\e]0;\u@\h \w \007\]';
        ;;
    *)
        TITLEBAR="";
        ;;
esac

PS1="[$DGREY\A $STARTCOLOR\u$GREY@$STARTCOLOR\h$GREY] <$DGREY\# $YELLOW\w/$GREY> $GREY$TITLEBAR"

The following is the result of this work. The prompt shows:

As a regular user, the username and hostname are Bold Green
As the root user, the username and hostname are Bold Red
The title bar of the window shows the username, host and current path

Dark Grey Date \A
Bright Green Username \u
Bright Green Hostname \h
Dark Grey Current Session Command Count \#
Yellow Path \w (I use the / to finish it off)

I left the default directory colors alone except for changing the directories from Blue to Bold Blue.

Enjoy,

J
 

Attachments

  • Picture 4.png
    Picture 4.png
    112.2 KB · Views: 235
Update: I found two small issues in the PS1 prompt from above that are corrected with:

PS1="$GREY[$DGREY\A $STARTCOLOR\u$GREY@$STARTCOLOR\h$GREY] <$DGREY\# $YELLOW\w/$GREY> $ENDCOLOR$TITLEBAR"

I also found another thread on this forum suggesting iTerm from Sourceforge. Apple's terminal app does most of what iTerm does, but the two things I like about iTerm are that it allows transparent windows with Blur and it copies on select.

Transparent terminal windows are cool, but I find that I have to set the transparency threshold pretty low otherwise when the terminal window is over top of a bright background, the contents of the terminal window become difficult to read.

Copy on select is very cool, and I missed that feature from putty on Windows. Glad to have that back.

Here's a picture of the fixed prompt and the iTerm blur.
 

Attachments

  • Picture 1.png
    Picture 1.png
    86.7 KB · Views: 138
Font Type?

What Font Type do you use. I currently use Monaco.
Also my colors seem to be far more shrill, I would like them a little softer like you screenshot shows them too.
 
What Font Type do you use. I currently use Monaco.
Also my colors seem to be far more shrill, I would like them a little softer like you screenshot shows them too.

check "use bright colors for bold text" in the terminal prefs
 
What Font Type do you use. I currently use Monaco.
Also my colors seem to be far more shrill, I would like them a little softer like you screenshot shows them too.

Monaco 12pt, Antialias text, Display ANSI, Use bright colors for bold text.

J
 
Monaco 12pt, Antialias text, Display ANSI, Use bright colors for bold text.

J

Thnx. Colors still seem a little of(I guess depends a little on displays too), but it is far better now.
Could have thought of that myself thouhg, but just skipped over it when I opened the preferences the last time ;-).
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.