โ€œ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

Installation:

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 โ€”

Install-Module -Name oh-my-posh

Alternatively, you can use the installation command [Figure 1] given by the documentation itself (thereafter same procedure)โ€”

Install-Module oh-my-posh -Scope CurrentUser

oh-my-posh Module Installation Command

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)]โ€”

1) [๐™”] ๐™”๐™š๐™จ
2) [A] Yes to All
3) [N] No
4) [L] No to All
5) [S] Suspend
6) [?] Help

Type โ€˜yโ€™ or โ€˜Yโ€™ [Figure 2 (Yellow Box)] and press enter to allow the module to be installed.

Untrusted Repository warning (Red Box) and the needed input (Yellow Box)

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] โ€”

Window saying the package is being installed

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 โ€”

Get-PoshThemes

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] โ€”

All Available theme-preview
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)โ€”

Set-PoshPrompt -Theme microverse-power

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 โ€”

notepad $profile

It will open a notepad window. Copy-paste the above theme-setting command [Figure 5], i.e. โ€”

Set-PoshPrompt -Theme microverse-power

Setting the theme as permanent

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)โ€”

Import-Module oh-my-posh
oh-my-posh init pwsh --config https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/1_shell.omp.json | Invoke-Expression

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 โ€”

aritraroy.omp.json
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"blocks": [
{
"type": "prompt",
"alignment": "left",
"segments": [
{
"type": "os",
"style": "plain",
"foreground": "#5aeea4"
},
{
"type": "session",
"style": "powerline",
"powerline_symbol": "\uE0B0",
"foreground": "#18f123",
"background": "#242424",
"properties": {
"display_host": false,
"postfix": " "
}
},
{
"type": "battery",
"style": "powerline",
"powerline_symbol": "",
"foreground": "#193549",
"background": "#f36943",
"properties": {
"battery_icon": "",
"color_background": true,
"charged_color": "#50cdff",
"charging_color": "#ffa32a",
"discharging_color": "#ff0000",
"postfix": "\uF295 "
}
},
{
"type": "time",
"style": "powerline",
"powerline_symbol": "\uE0B0",
"foreground": "#ffe866",
"background": "#242424",
"properties": {
"time_format": " 2006-01-02",
"prefix": ""
}
},
{
"type": "time",
"style": "powerline",
"powerline_symbol": "",
"foreground": "#242424",
"background": "#ffe866",
"properties": {
"time_format": "15:04:05",
"prefix": " "
}
},
{
"type": "path",
"style": "powerline",
"powerline_symbol": " ",
"foreground": "#f84e78",
"background": "#242424",
"properties": {
"prefix": "\uE5FF ",
"style": "full",
"folder_separator_icon": "/"
}
},
{
"type": "shell",
"style": "powerline",
"powerline_symbol": "\uE0B0",
"foreground": "#ffffff",
"background": "#0077c2",
"properties": {
"prefix": " \uFCB5 "
}
},
{
"type": "git",
"style": "powerline",
"powerline_symbol": "\uE0B0",
"foreground": "#462e00",
"background": "#fffb00",
"properties": {
"display_status": true,
"display_stash_count": true,
"display_upstream_icon": true,
"prefix": " "
}
},
{
"type": "exit",
"style": "powerline",
"powerline_symbol": "\uE0B0",
"foreground": "#242424",
"background": "#33DD2D",
"properties": {
"display_exit_code": false,
"always_enabled": true,
"color_background": true,
"error_color": "#f1184c",
"prefix": " \ufc8d"
}
}
]
},
{
"type": "newline"
},
{
"type": "prompt",
"alignment": "left",
"segments": [
{
"type": "text",
"style": "plain",
"foreground": "#ee00e2",
"properties": {
"prefix": "",
"text": "\u21d2"
}
}
]
}
],
"final_space": true
}
Customized theme (aritraroy) used by me

The above code will give you the result [Figure 6] like the following (Iโ€™ve blurred the exact folder path for my own reason) โ€”

PowerShell screenshot after installing customized aritraroy theme - 1 PowerShell screenshot after installing customized aritraroy theme - 2

Figure 6: PowerShell screenshot after installing customized aritraroy theme

Customization Procedure:

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.

Blocks:

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

[1]. type: Now, as you see, type can be of three types (I used prompt as type) โ€”

๐š) ๐ฉ๐ซ๐จ๐ฆ๐ฉ๐ญ: renders one or more segments
๐›) ๐ซ๐ฉ๐ซ๐จ๐ฆ๐ฉ๐ญ: one or more segments aligned to the right of the cursor
๐œ) ๐ง๐ž๐ฐ๐ฅ๐ข๐ง๐ž: inserts a new line

[2]. alignment: You can align the elements right or left using the alignment option (I used left as alignment).

[3]. 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).

[4]. 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 โ€”

๐Ÿญ) ๐˜๐˜†๐—ฝ๐—ฒ: ๐—ผ๐˜€-shows operating system you are using
๐˜€๐—ฒ๐˜€๐˜€๐—ถ๐—ผ๐—ป-shows user name and host name
๐—ฏ๐—ฎ๐˜๐˜๐—ฒ๐—ฟ๐˜†-shows battery status
๐˜๐—ถ๐—บ๐—ฒ-shows date and time
๐—ฝ๐—ฎ๐˜๐—ต-shows the folder path
๐˜€๐—ต๐—ฒ๐—น๐—น-shows which type of shell you are using
๐—ด๐—ถ๐˜-shows git status (enabled with posh-git)
๐—ฒ๐˜…๐—ถ๐˜-shows the display status (error/succesful)
๐Ÿฎ) ๐˜€๐˜๐˜†๐—น๐—ฒ: ๐—ฝ๐—ผ๐˜„๐—ฒ๐—ฟ๐—น๐—ถ๐—ป๐—ฒ-background(previous one)foreground(current one)
๐—ฝ๐—น๐—ฎ๐—ถ๐—ป-colored text on a transparent background
๐—ฑ๐—ถ๐—ฎ๐—บ๐—ผ๐—ป๐—ฑ-ifferent starting and ending symbol
๐Ÿฏ) ๐—ฝ๐—ผ๐˜„๐—ฒ๐—ฟ๐—น๐—ถ๐—ป๐—ฒ_๐˜€๐˜†๐—บ๐—ฏ๐—ผ๐—น: text character to use when style "powerline" is selected
๐Ÿฐ) ๐—ณ๐—ผ๐—ฟ๐—ฒ๐—ด๐—ฟ๐—ผ๐˜‚๐—ป๐—ฑ ๐—ฎ๐—ป๐—ฑ ๐—ฏ๐—ฎ๐—ฐ๐—ธ๐—ด๐—ฟ๐—ผ๐˜‚๐—ป๐—ฑ: to set foreground and background colour
๐Ÿฑ) ๐—ฝ๐—ฟ๐—ผ๐—ฝ๐—ฒ๐—ฟ๐˜๐—ถ๐—ฒ๐˜€: to set different properties for different type like prefix, postfix, time format, display host, charging colour, discharging colour etc.

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.

Note

  • โ€ข If you somehow came up with an execution policy error like Figure 7, please go through the following two articles to avoid that error โ€”

Execution Policy 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.

โ• โ• โ•

Thank you for reading.

I hope you found this โ€œOh-My-Posh V3 is Out in the Marketโ€ article helpful. Please share if you like and leave any comment to let me know your thoughts.

You can connect with me on LinkedIn, Instagram, Twitter or GitHub.