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

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.
Software Development
by Jey Geethan | August 14, 2019

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.


Related Articles

Software Development

Solving - xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

by Jey Geethan | March 16, 2018
Solving - xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
If you recently updated to macOS High Sierra and tried to run git commands you would face this error
Software Development

iTerm2 vs Plain Old Terminal - Which One Is The Best?

by Jey Geethan | August 28, 2017
iTerm2 vs Plain Old Terminal - Which One Is The Best?
Have you ever wondered if you have an alternative that will be better and useful than the default terminal?