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

[VB.NET] Finding whether its Design Mode or Runtime Mode for Forms

by Jey Geethan | November 06, 2008
[VB.NET] Finding whether its Design Mode or Runtime Mode for Forms
Sometimes, while creating controls, either by Inherited Controls or UserControls, we will be required to skip a piece of code depending upon the design time or runtime mode.
Software Development

Ruby on Rails Engine - How To Keep Your Engine Migrations Abstracted From Your Host Rails App

by Jey Geethan | January 16, 2019
Ruby on Rails Engine - How To Keep Your Engine Migrations Abstracted From Your Host Rails App
Have you ever worked on building a Rails Engine and wanted to keep the models, the migrations and everything inside the engine rather than using a generator to copy paste them into your host Rails App?