Join our Discord Server
Ajeet Raina Ajeet Singh Raina is a former Docker Captain, Community Leader and Distinguished Arm Ambassador. He is a founder of Collabnix blogging site and has authored more than 700+ blogs on Docker, Kubernetes and Cloud-Native Technology. He runs a community Slack of 9800+ members and discord server close to 2600+ members. You can follow him on Twitter(@ajeetsraina).

Easy way to colorify Your Shell Prompt Experience on The Mac

3 min read

Have you ever attended a developer conference and marveled at the colorful and eye-catching terminal prompts displayed by presenters? If you’ve wondered how to make your Mac terminal look equally cool and personalized, you’re in the right place. In this guide, we’ll walk you through the steps to colorify your shell prompt experience on macOS.

Image11

The Concept

Traditionally, configuring your shell prompt involved either intricate custom scripts per theme or navigating a labyrinth of command-line configuration switches. It could be cumbersome and required a deep understanding of the underlying mechanisms.

Oh My Posh seeks to simplify this process by introducing a novel concept – a single configuration file that can be effortlessly shared across platforms and users. This approach eliminates the need for users to delve into the intricacies of prompt customization.

Deconstructing the Prompt

If you’ve ever admired complex and aesthetically pleasing prompts like Agnoster or Paradox, you’d notice they share a common structure. They consist of a few fundamental building blocks, each housing one or more segments that display specific information.

The brilliance of Oh My Posh lies in its ability to deconstruct your prompt into these building blocks. These blocks, in turn, are composed of segments, and this hierarchy is mirrored in Oh My Posh’s configuration.

In essence, you can think of your prompt as a carefully orchestrated symphony, where each block and segment plays a unique role in displaying vital information and enhancing your shell’s functionality.

Oh My Posh in Action

Oh My Posh‘s approach to prompt customization simplifies the process for users while retaining the flexibility to create intricate and visually appealing prompts. Whether you’re a seasoned shell aficionado or a newcomer looking to elevate your command-line experience, Oh My Posh offers a powerful and accessible solution.

With its innovative configuration model and focus on modular blocks and segments, Oh My Posh empowers users to craft personalized prompts that not only look great but also provide valuable insights and functionality.

In the world of shell customization, Oh My Posh is a game-changer, putting the power of prompt customization in the hands of all users, regardless of their level of expertise. So, if you’re ready to transform your shell prompt into a work of art, Oh My Posh is here to help you achieve just that.

Getting Started

Install Homebrew

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Install iTerm

iTerm can now be installed with brew by running the following command:

brew install --cask iterm2

Install Oh My Zsh

Zsh is the default shell that comes pre-installed on all macOS systems since macOS Catalina. Zsh works as an interpreter that translates your terminal commands into instructions for your operating system to run. Zsh on itself isn’t very powerful. To improve this, we will install Oh My Zsh which is a framework for managing your Zsh configuration. This will allow you to install plugins for your Zsh configuration.

To install Oh My Zsh, simply open up your terminal emulator of choice and run the following command:

sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

Now that Oh My zsg is installed, you can go ahead and configure your terminal and shell to get the prompt to look exactly like you want.

Install Oh My Posh

You can install the Oh My Posh theming engine with Homebrew by executing the following command:

brew install jandedobbeleer/oh-my-posh/oh-my-posh

Install Font

Oh My Posh recommends installing Nerd Fonts. These fonts are patched to include beautiful icons which will be displayed in your terminal prompt. Fonts can be installed with the built-in Oh My Posh command.

oh-my-posh font install

After running this command, you will be prompted to select a specific font.

Image9

We will choose Meslo, since Oh My Posh recommends this font for its theming engine.

eval "$(oh-my-posh init zsh --config $(brew --prefix oh-my-posh)/themes/M365Princess.omp.json)"
source ~/.zshrc

Don’t forget to rerun the command source ~/.zshrc to activate your changes.

Image8

The process you followed sets up Oh My Posh for your current shell session only. To make the changes permanent for your iTerm2 sessions on Mac, you need to add the initialization command to your Zsh configuration file. Here’s how:

Open your Zsh configuration file:

In your iTerm2 window, run the following command:

nano ~/.zshrc

This opens the .zshrc file in your default text editor (likely Nano).

Add the initialization command:

Paste the following line at the end of the file, replacing “M365Princess.omp.json” with your desired theme config file (if different):

eval "$(oh-my-posh init zsh --config $(brew --prefix oh-my-posh)/themes/M365Princess.omp.json)"

Save and close the file:

In Nano, press Ctrl+O to save the changes, then Ctrl+X to exit.
Reload your Zsh configuration:

In your iTerm2 window, run the following command to apply the changes:

source ~/.zshrc

Now, whenever you open a new iTerm2 session, your Zsh shell will automatically initialize Oh My Posh with your chosen theme. You won’t need to run the eval command manually anymore.

Conclusion

With these simple steps, you’ve colorified your shell prompt on your Mac, giving it a personalized and eye-catching appearance.

Have Queries? Join https://launchpass.com/collabnix

Ajeet Raina Ajeet Singh Raina is a former Docker Captain, Community Leader and Distinguished Arm Ambassador. He is a founder of Collabnix blogging site and has authored more than 700+ blogs on Docker, Kubernetes and Cloud-Native Technology. He runs a community Slack of 9800+ members and discord server close to 2600+ members. You can follow him on Twitter(@ajeetsraina).
Join our Discord Server
Index