Software Development

How to get informative, color prompts on Mac Terminal or iTerm2

This article talks about how to get color prompts on your terminal and add some informative things like current git branch and distinctive colors for current path, username etc.
by Jey Geethan | August 14, 2019
How to get informative, color prompts on Mac Terminal or iTerm2

The default prompts on the terminal and iTerm2 are good but are not very descriptive and useful. I wanted to create a prompt that shows the following:

  • Current path
  • Current git branch (if within a git repo)
  • Username
  • All the above in very distinctive colors

This is important so that I instinctively know where I am, what I am doing. Also I do not want to commit to the wrong branch. Sometimes I keep working in a wrong branch to figure out a bug only until later to know that the branch was wrong. So I wanted to know the branch on my terminal all the time. I scripted the following to solve all these problems.

Notes:

  1. You are using bash as your login shell
  2. Currently Mac uses zsh as the default login shell and you may have to change it bash for the following script to work
  3. Source the script file for the first time use

All you have to do is to use the following script in your ~/.bash_profile

Gist link: https://gist.github.com/jeygeethan/a6d261d32cea97e9a52b82f48989c07f

Happy development!

If you like my content, be sure to like and leave a comment.


Jey Geethan

Jey Geethan is a poet, author and an entrepreneur.