I'm new to OS X, having just gotten a Mac after working with Ubuntu Linux for some time. Among the many things I'm trying to figure out is the absence of colors in my terminal window - like the ones that are shown (on Linux) when running ls -la
or git status
...
I just can't figure out how to activate colors in my shell.
I know, this thread is old but the issue not.
Here is a solution I've found to enable the global terminal colors.
Edit your
.bash_profile
(since OS X 10.8) — or (for 10.7 and earlier):.profile
or.bashrc
or/etc/profile
(depending on availability) — in your home directory and add following code:CLICOLOR=1
simply enables coloring of your terminal.LSCOLORS=...
specifies how to color specific items.After editing
.bash_profile
, start a Terminal and force the changes to take place by executing:source ~/.bash_profile
Then go to
Terminal > Preferences
, click on theProfiles
tab and then theText
subtab and checkDisplay ANSI Colors
.Verified on Sierra (May 2017).
MartinVonMartinsgrün and 4Levels methods confirmed work great on Mac OS X Mountain Lion.
The file I needed to update was ~/.profile.
However, I couldn't leave this question without recommending my favorite application, iTerm 2.
iTerm 2 lets you load global color schemes from a file. Really easy to experiment and try a bunch of color schemes.
Here's a screenshot of the iTerm 2 window and the color preferences.
Once I added the following to my ~/.profile file iTerm 2 was able to override the colors.
Here is a great repository with some nice presets:
iTerm2 Color Schemes on Github by mbadolato
Bonus: Choose "Show/hide iTerm2 with a system-wide hotkey" and bind the key with BetterTouchTool for an instant hide/show the terminal with a mouse gesture.
When I worked on Mac OS X in the lab I was able to get the terminal colors from using Terminal (rather than X11) and then editing the profile (from the Mac menu bar). The interface is a bit odd on the colors, but you have to set the modified theme as default.
Further settings worked by editing
.bashrc
.If you are using tcsh, then edit your
~/.cshrc
file to include the lines:Where, like Martin says, LSCOLORS specifies the color scheme you want to use.
To generate the LSCOLORS you want to use, checkout this site
Check what $TERM gives: mine is xterm-color and ls -alG then does colorised output.
You can use the Linux based syntax in one of your startup scripts. Just tested this on an OS X Mountain Lion box.
eg. in your
~/.bash_profile
This gives you a nice colored prompt. To add the colored
ls
output, you can addalias ls="ls -G"
.To test, just run a
source ~/.bash_profile
to update your current terminal.Side note about the colors: The colors are preceded by an escape sequence
\e
and defined by a color value, composed of[style;color+m]
and wrapped in an escaped[]
sequence. eg.\[\e[0;31m\]
\[\e[1;31m\]
\[\e[0m\]
I always add a slightly modified color-scheme in the root's .bash_profile to make the username red, so I always see clearly if I'm logged in as root (handy to avoid mistakes if I have many terminal windows open).
In
/root/.bash_profile
:PS1='\[\e[0;31m\]\u\[\e[0m\]@\[\e[0;32m\]\h\[\e[0m\]:\[\e[0;34m\]\w\[\e[0m\]\$ '
For all my SSH accounts online I make sure to put the hostname in red, to distinguish if I'm in a local or remote terminal. Just edit the
.bash_profile
file in your home dir on the server.. If there is no.bash_profile
file on the server, you can create it and it should be sourced upon login.