color coding mac terminal

11

5

how do i get the mac terminal to display colors? i.e. in fedora when i use ls it color codes the results based on if it's a file or folder. similar results on mac?

tekknolagi

Posted 2011-01-13T05:11:16.837

Reputation: 1 130

Edited question, since the answers suggest the problem is ls specific. – Daniel Beck – 2011-01-13T06:30:29.763

2Can you provide examples other than ls which you'd like to have colorized and in what way? There are various colorizers that can be used in pipelines to highlight text based on regexes either in config files or on the command line. – Paused until further notice. – 2011-01-13T16:57:33.427

in VI or VIM, especially in syntax coloring – tekknolagi – 2011-01-14T00:30:07.967

Answers

4

You can change your shell colors in Terminal's preferences.

alt text


With these settings, you get these colors (not usually using colored ls, so I don't care):

alt text


I don't understand what the issue is here. Colored command output is active by default. The only thing you can/need to do yourself is give normal and bold text different default colors, and actually use the colored variants (e.g. ls -G) of your commands.

For vim: :syntax on in vim. Or append syntax on to .vimrc.

Daniel Beck

Posted 2011-01-13T05:11:16.837

Reputation: 98 421

1display ANSI colors? – tekknolagi – 2011-01-14T00:29:36.563

@tekknolagi This option enables colored output e.g. of ls -G. Toggle it with a Terminal window open to see the effect. You can also select different default colors for regular and bold text. – Daniel Beck – 2011-01-14T08:32:37.973

14

Add, these lines to the end of your ~/.bash_profile

alias ls='ls -G'
export CLICOLOR=1
export LSCOLORS=Gxfxcxdxbxegedabagacad

As you can see, customizing them is a bit of a pain, but there's a website that helps with that... http://geoff.greer.fm/lscolors/

Now when you open the Terminal it will have colors in ls

ocodo

Posted 2011-01-13T05:11:16.837

Reputation: 1 672

do i have to do that for every single command i want? – tekknolagi – 2011-01-13T05:27:24.613

No, your ~/.bash_profile is used to add settings to your Terminal sessions, it is loaded every time a Terminal window is shown. It's a text file, you just add those lines to the end, and save it. Then start up Terminal, or restart it, and your settings are active. – ocodo – 2011-01-13T05:36:23.160

not what i meant. if i want to color code other commands – tekknolagi – 2011-01-13T06:31:28.780

i am very familiar with the bash profile – tekknolagi – 2011-01-13T06:34:11.773

Only if they have their own color profile, which commands are you interested in? – ocodo – 2011-01-13T20:12:57.403

5

Use the -G switch to ls on Mac:

ls -G

If you'd like the standard ls to always be colored, add this to your ~/.bash_profile:

alias ls='ls -G'

John T

Posted 2011-01-13T05:11:16.837

Reputation: 149 037