“Walking through darkness with thoughts full of colors…” ― Prajakta Mhadnak
Perhaps the above line is the best description of the most wanted work experience for all the programmers. Every creature in the world decorates its own living space — there we are, human after all!!!. And who doesn’t know IDE and terminals are the living worlds in the field of programming and development? So, each IDE provides a customisable environment (if you are not from Adam-Eve’s age — using notepad as an IDE😉). But those who are using the terminal as their living (!working) world was abandoned for years until Robby Russell built oh-my-zsh. If you are using Ubuntu, you can consider the following tutorial guide written by Michiel Mulders —
Or if you are using macOS, then here goes the step by step installation guide for you —
But Alas!!! If you are using Windows PowerShell, then sorry, oh-my-zsh is not for you. Here Jan De Dobbeleer came forward with his oh-my-posh module for us (Windows User). I think you have read about oh-my-posh V2 and posh-git in my previous article…Not yet? Read my earlier article — you’ll get to know how to install posh-git (!Highly recommended for git users🙌🙌🙌️) —
Enough of patience? Hold on✋✋✋!!! I’m diving into the details right now —
Fundamental Differences Between V2 and V3
• V2 was applicable for only Windows PowerShell. But V3 is available for Windows, macOS and Linux also.
• The configuration is changed from $ThemeSettings to .json to ensure easy customisation.
• More easy installation procedure.
oh-my-posh V3: Step-by-Step Guide
I’ll be using Windows PowerShell for this guide. A PowerShell module has already been there for the effortless installation procedure. Just paste the following command in your PowerShell and press enter —
Alternatively, you can use the installation command [Figure 1] given by the documentation itself (thereafter same procedure)—
Figure 1: oh-my-posh Module Installation Command
Though this installation process can be done without the Administrator Mode, it’s better to do all this staff in Administrator Mode. While installing, you can see a confirmation message for the complete installation saying, ‘You are installing the modules from an untrusted repository.’ You will have the following six options [Figure 2 (Red Box)]—
Type ‘y’ or ‘Y’ [Figure 2 (Yellow Box)] and press enter to allow the module to be installed.
Figure 2: Untrusted Repository warning (Red Box) and the needed input (Yellow Box)
After that, you can see a window popping up saying that the package is being installed [Figure 3] —
Figure 3: Window saying the package is being installed
Visualising All The Themes:
Now, once you have installed the module, you can view all the available themes provided by the module by using the following command in your PowerShell terminal —
oh-my-posh V3 provides a total no of 38 themes. You can see all the available themes are coming up, showing their respective theme-preview [Figure 4] —
Figure 4: All Available theme-preview
Setting Your Theme:
Now you can use the following command to set a theme as your terminal theme (microverse-power is a theme name provided by the oh-my-posh module itself)—
But wait ✋✋✋, it is not done yet. If you leave here, you have to set the theme again when you open the terminal next time. If you want to set the theme as permanent, i.e. when you open the terminal, the theme will be automatically set up for you, then you’ll have to save the theme configuration in the profile. For that, copy-paste the following command in your terminal and hit enter —
It will open a notepad window. Copy-paste the above theme-setting command [Figure 5], i.e. —
Figure 5: Setting the theme as permanent
Save the notepad file and run the command . $PROFILE and finally reload your terminal to see the changes. At this point, you are good to go. Most people will be happy with all the available themes.
⁕ ⁕ ⁕
Getting an error: oh-my-posh command not found?
It’s because oh-my-posh no longer support PowerShell Modules. But don’t worry, they have given the solution. You just have to migrate oh-my-posh to enable it on your device. The process is very simple. Just copy-paste the following commands into your profile file (to use 1_shell)—
Now, if you want to use other themes, you can change the name of the theme in the link. You can get all the themes on their official website’s theme section.
⁕ ⁕ ⁕
But if you want to be unique, then follow me along. I have customized it to adjust my choice, and here it goes —
The above code will give you the result [Figure 6] like the following (I’ve blurred the exact folder path for my own reason) —
Figure 6: PowerShell screenshot after installing customized aritraroy theme
Basically, oh-my-posh renders your prompt based on the definition of blocks (like Lego), which contain one or more segments. Now it’s more comfortable for you(!as a beginner) to modify one theme or merge two or more themes than to build from scratch. I have also combined two themes (microverse-power and jandedobbeleer), which gave me the above result.
Under General Settings, an essential part is “blocks”. Now under “blocks”, you can add the following elements —
• type: prompt ∣ rprompt ∣ newline
• alignment: left ∣ right
• vertical_offset: int
• horizontal_offset: int
• segments: array of one or more segments
. type: Now, as you see, type can be of three types (I used prompt as type) —
. alignment: You can align the elements right or left using the alignment option (I used left as alignment).
. vertical_offset & horizontal_offset: You can also give vertical and horizontal offset(space) using the vertical_offset and the horizontal_offset options, respectively (I didn’t use these parameters).
. segments: Now, segments are the most important part of this script. This part provides many parameters like —
• type: string
• style: powerline ∣ plain ∣ diamond
• powerline_symbol: string
• invert_powerline: boolean
• leading_diamond: string
• trailing_diamond: string
• foreground: string
• foreground_templates: array of string values
• background: string
• background_templates: array of string values
• properties: array of Property: string
Now I’m not going to discuss all the parameters. I’ll talk about the most common and interesting ones —
Also, you can use Nerd Fonts to include icons in your text part to look cooler. But all icons are not accepted in all fonts. There is no specific layout in which font will support which icons. You have to go through a try and error process to come up with the best one. You can also find different icons from charbase.com —
Now, to implement your custom theme, save the file as filename.omp.json and save it in any folder you like. Copy the folder path and change the URL in your profile with the copied path following filename.omp.json and again run the . $PROFILE command. Reload your terminal to see your customized theme.
- • If you somehow came up with an execution policy error like Figure 7, please go through the following two articles to avoid that error —
Figure 7: Execution Policy Error
- • If you want to know more about the customization of the oh-my-posh module, then kindly go through their whole documentation.
⁕ ⁕ ⁕