Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

People also ask

How do you permanently change the color of the Terminal on a Mac?

To do so, navigate to the Terminal's Preferences screen. From here, select the Profiles tab. This section will let you adjust the appearance of the Terminal window. You're able to change the background and text color, text-rendering options, font sizes and typefaces, the cursor type, selection color, and ANSI colors.

How do I make bash colorful on Mac?

To make the bash terminal console more colorful, you need to create or edit a ~/. bash_profile file, and configure the LSCOLORS value. See following example to show you how to create a new . bash_profile and put it in your home directory.

How do you make a black and green Terminal on a Mac?

Use Text preferences in Terminal to change the font, text, color, and cursor options for a Terminal window profile. To change these preferences in the Terminal app on your Mac, choose Terminal > Preferences, click Profiles, select a profile, then click Text.

How do I make my Mac Terminal dark?

Turn on Dark ModeChoose Apple menu  > System Preferences, click General, then select one of the Appearance options at the top of the window: Light: Use the light appearance. Dark: Use the dark appearance.


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.


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}\]$ '

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.


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".