How to configure Mac OS X term so that git has color?

Viewed 77255

I've seen a Mac OS X git demo online in which it's configured to have multiple colors.

For example, his prompt is amber, his ls directory is purple and his git diff output has ~ 4 colors (pink, light green, red, pale yellow).

Can you tell me how can I configure Mac OS X terminal to achieve that? It's definitely Mac OS X Terminal.app, not iTerm.

6 Answers

To display color in the output of git diff, you need to configure git. Try running

$ git config --global color.diff true

to set your $HOME/.gitconfig appropriately.

It is not normally something you configure the terminal to do... The terminal is unaware of what it is showing but try this in your shell (if you're using bash, in some other shells you don't export but call setenv or something else):

export CLICOLOR=1
export TERM=xterm-color

You can then use LSCOLORS generator to setup something that you can export using something like:

export LSCOLORS=fxfxcxdxbxegedabagacad

(the above should give you purple directories)

When you're done and satisfied with the result, add the three lines to either your /etc/bashrc or the .bashrc file in your user's home directory.

Edit: Also, in your terminal, make sure the checkbox "Display ANSI colors" (on the "Text" page) is checked.

For colored ls output I would recommend installing the gnu coreutils and using that version of ls instead. For either version of ls you'll need to pass the correct flag to it, which is --color for the gnu version or -G for the standard OS X version. So you can do something like

alias ls='ls --color'

in your .bashrc.

To color your prompt you'll need to use the correct colors codes for your terminal, but mine uses

PROMPT="$(print '%{\e[0;38m%}%{\e[1;1m%]%}[%m:%c] %n%%%{\e[0m%}') "

to produce

[hostname:directory] username%

in bold white.

Related