โ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 โ
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] โ
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. โ
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
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) โ
[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 โ
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 โ
- โข If you want to know more about the customization of the oh-my-posh module, then kindly go through their whole documentation.
โ โ โ