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.
William Purcell's answer only enables color for the 'git diff' command. Do this to enable colors for all git commands:
$ git config --global color.ui true
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.
This is what I use in my .profile file. Works like a charm because it allows me to see the current git branch as well as its state through the color.
If you want to modify it please note that it's important to escape color codes in order to avoid line feed problems in long lines.
# Setting GIT prompt
c_cyan=`tput setaf 6`
c_red=`tput setaf 1`
c_green=`tput setaf 2`
c_sgr0=`tput sgr0`
branch_color ()
{
if git rev-parse --git-dir >/dev/null 2>&1
then
color=""
if git diff --quiet 2>/dev/null >&2
then
color=${c_green}
else
color=${c_red}
fi
else
return 0
fi
echo -n $color
}
parse_git_branch ()
{
if git rev-parse --git-dir >/dev/null 2>&1
then
gitver="["$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p')"]"
else
return 0
fi
echo -e $gitver
}
#It's important to escape colors with \[ to indicate the length is 0
PS1='\u@\[${c_red}\]\W\[${c_sgr0}\]\[\[$(branch_color)\]$(parse_git_branch)\[${c_sgr0}\]$ '
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.
Open the terminal app, then open the preferences dialogue either through the menu (Terminal -> Preferences) or by pressing Command+,. Once the preferences dialogue opens, select the terminal style from the pane on the left, select Text from the button bar, than make sure the "Display ANSI colors" check box is checked.
That will enable the colors on the terminal. To get colors in the output on the terminal, you will need to embed ANSI color commands in the data being sent to the terminal. How this is done is dependent on the commands. For example (as was shown above) the ls
command has a colors option. For the color codes, do a google lookup for "ansi color".