Mac OS X Terminal Customization: Colors

- 5 mins

The out-of-the-box configuration of the Terminal application in Mac OS X is quite simple/plain. If you don’t use it frequently, it will be ok to leave it in that way. However, if you continuously open Terminal, it will be great to customize it so you can be more productive.

By default, this is how Terminal application looks like (Basic Profile):


As you can see, it is based just in black text and white background but you can give more life to Terminal using colors and this article will explain how to customize it according to your own tastes.

Mac OS X Terminal

First, let’s change the default profile to other one . To do so, open a new Terminal and go to Terminal -> Preferences -> Profiles. In my case, I like the Pro Profile (cool name!) because it looks like an old terminal with white text and black background.


Besides changing the profile, you should consider enabling the following options in Text Tab:

Configuring BASH

Now it is time to configure the BASH prompt; that means, change the environment variable $PS1. Let’s check its default value:

optimus:~ modlost$ echo $PS1
\h:\W \u\$

The prompt shows the hostname (\h), colon (:), current directory base name (\W), username (\u) and # or $ symbol ($). You can find more information about all the backslash-escape especial characters available for this variable in the unix man page for BASH section PROMPTING. In this case, we are going to use these options:

In my experience a simple (short) prompt works best and Debian distribution defines one by default that I really like. Take a look at it executing the following command:

optimus:~ modlost$ PS1='\u@\h:\w\$ '

Looks great but it will be better with colors. To help you decide which color you would like, you can use this shell script to print the 16 ANSI color codes. Execute it in a Terminal using your prefered profile so you can decide which colors are best for you.


Now you can choose where you want to change colors coping those codes in $PS1. Debian distribution define a nice colors, let’s use the same:

modlost@optimus:~$ PS1=‘\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[m\]\$ ‘


To make these changes permanent you should define $PS1 in .bash_profile because Terminal starts login shells. At the end of the next section you will find a complete ~/.bash_profile.

Configuring ls and grep commands

If you use the Terminal a lot, it is probably that ls is one of your most used commands so adding color will be awesome. To do that, you will have to define a new enviroment variable LSCOLORS containing a string that has the following structure:

  1. directory
  2. symbolic link
  3. socket
  4. pipe
  5. executable
  6. block special
  7. character special
  8. executable with setuid bit set
  9. executable with setgid bit set
  10. directory writable to others, with sticky bit
  11. directory writable to others, without sticky bit

Each one of those items contains two characters, one for the foreground and the other for the background. The color codes you can use are:

For Pro Profile that uses dark background, this could be one good color combination:

modlost@optimus:~$ LSCOLORS=ExFxBxDxCxegedabagacad

But it doesn’t work unless you add the -G option in every ls execution, so the best way to do that is defining aliases:

modlost@optimus:~$ alias ls='ls -G'
modlost@optimus:~$ alias ll='ls -l'
modlost@optimus:~$ alias la='ls -A'
modlost@optimus:~$ alias l='ls -CF'

Execute them to test the configuration:


Another quite common command is grep and it also supports colors, you just need to define the following alises:

modlost@optimus:~$ alias grep='grep --colour=auto'
modlost@optimus:~$ alias fgrep='fgrep --colour=auto'
modlost@optimus:~$ alias egrep='egrep --colour=auto'

Execute a little example and you will see how useful is enabling colors in grep:


So the final ~/.bash_profile is the following:

export PS1="\[\e]0;\a\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[m\]\$ "

export LSCOLORS=ExFxBxDxCxegedabagacad
alias ls='ls -G'
alias grep='grep --colour=auto'
alias fgrep='fgrep --colour=auto'
alias egrep='egrep --colour=auto'

alias ll='ls -l'
alias la='ls -A'
alias l='ls -CF'

Configuring Vim

Finally, if you use Vi Editor a lot, you should create a ~/.vimrc file with the following content:

syntax on
set background=dark

And the result will be the following:


Next Steps

Now your Mac OS X Terminal Application has a lot of colors and that will help you every day and make you more productive.

Happy Hacking!!!!

Abner Ballardo

Abner Ballardo

In permanent beta: learning, adapting and evolving

rss facebook twitter github gitlab youtube mail spotify lastfm instagram linkedin google google-plus pinterest medium vimeo stackoverflow reddit quora quora