The default MAC terminal looks very lame, doesn’t matter which theme you are using. As a developer you need visibility in the terminal; thus, things should be colorful like ubuntu. This article gives you proper solution for that without installing any custom theme.

The article contains the following:

  1. A readymade snippet to change the terminal colors.
  2. The snippet will make root, correct directory of different colors.
  3. git branch will be displayed.
  4. Explaining how the snippet works.
  5. Providing details to edit the snippet.

custom mac terminal

Make MAC terminal colorful in 3 steps

Choose any black theme first as the color combination of my snippet is dark theme friendly. You can change the theme by going to the ‘preferences’ menu.

Step 1:

Open terminal. Edit the file .bash_profile (if os version 10.8 and higher) or .profile (for lower than 10.8). You can run the following command to open the file in vim.

vim .bash_profile

Step 2:

Go to edit mode by pressing 'i'. Append the following code in the file.

export CLICOLOR=1
export LSCOLORS=GxBxCxDxexegedabagaced

parse_git_branch() {
   git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'

export PS1="\e[0;35m->> \e[1;34m\W\e[0;32m\$(parse_git_branch)\e[0;37m $ "

Step 3:

Save the file and quit. To do this press escape key and write the following and enter.


Now open a new terminal window and the changes will be reflected.

How did the customization worked?

By setting CLLICOLOR=1 you are enabling colors. LSCOLORS is the variable where you will define which file should display what color. We will discuss afterwards how that ugly little line did all those.

parse_git_branch() is a custom function which is used to get the current git branch by running a shell command of git itself.

PS1 is the prompt line; the default line printed. I've customized it from 'user@host:currentDirectory $' to '->> CurrentDirectory $'. Those ugly \e[0;35m etc are nothing but colors. Will discuss more about the colors afterwards.

This is a little overview of the snippet. The section below will describe more about color customization.

The snippet has some color combination of my choice. Now what if you don't like those and want to color according to your choice? Well, you just have to know how the coloring is done in LSCOLORS and PS1. What code means which color and also a knowledge of positions.

Describing LSCOLORS

LSCOLORS is used to color the directory and file list. It provides you 11 positions, each with FB (foregroundColor backgroundColor) combination. Thus it contains 22 characters. Below is the details of which position means what.

  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

The colors for each position are placed as FB format as I said earlier. Below is the list which color means what.

  • a: black
  • b: red
  • c: green
  • d: brown
  • e: blue
  • f: magenta
  • g: cyan
  • h: light grey
  • A: bold black, usually shows up as dark grey
  • B: bold red
  • C: bold green
  • D: bold brown, usually shows up as yellow
  • E: bold blue
  • F: bold magenta
  • G: bold cyan
  • H: bold light grey; looks like bright white
  • x: default foreground or background

The colors mentioned above are ANSI colors, but according to the version of your OS (or terminal), the colors may differ a little.

Describing PS1:

As I said earlier, PS1 is the line printer by default, i.e. prompt. You can customize the string easily if you know the following details of what character means what.

  • \d: Date
  • \h: Host
  • \n: Newline
  • \t: Time
  • \u: Username
  • \W: Current working directory
  • \w: Full path to current directory
  • $(function_name): execute function

Changing the default prompt:

By default the prompt is user@host: currentDirectory $. Which is something like PS1= "\u@\h:\W $". Now I don't want that user@host, rather I want a static thing ->>. Or you may want to just CurrentDirectory. However you want it, by using the character shortcuts mentioned above you can easily implement it.

Now what remaining is coloring in prompt. You can use shell color codes to do it. The format of coloring is:

[color1]I am in color1 [color2] I'm color2

Below is the list of colors:

# Regular
'\e[0;30m' = Black
'\e[0;31m' = Red
'\e[0;32m' = Green
'\e[0;33m' = Yellow
'\e[0;34m' = Blue
'\e[0;35m' = Purple
'\e[0;36m' = Cyan
'\e[0;37m' = White

'\e[1;30m' = Black
'\e[1;31m' = Red
'\e[1;32m' = Green
'\e[1;33m' = Yellow
'\e[1;34m' = Blue
'\e[1;35m' = Purple
'\e[1;36m' = Cyan
'\e[1;37m' = White

'\e[4;30m' = Black
'\e[4;31m' = Red
'\e[4;32m' = Green
'\e[4;33m' = Yellow
'\e[4;34m' = Blue
'\e[4;35m' = Purple
'\e[4;36m' = Cyan
'\e[4;37m' = White

'\e[40m' = Black
'\e[41m' = Red
'\e[42m' = Green
'\e[43m' = Yellow
'\e[44m' = Blue
'\e[45m' = Purple
'\e[46m' = Cyan
'\e[47m' = White

'\e[0m' = Text Reset


Now you have the color codes, position details, default variables for host, path, user etc, git_branch_finder and also a details how to implement them in .bash_profile (or .profile). Hope you can easily customize your terminal as you want. Happy coding :)