For an awesome programming experience, customizing the working environment is the most wanted thing for a programmer. For that reason, every IDE provides different themes. But those, who work using the Windows PowerShell terminal, oh-my-posh and posh-git (recommended for Git users) are definitely the right and easy choice.

oh-my-posh is a PowerShell module that helps to decorate our PowerShell window using different in-built and self-customized themes. posh-git is a PowerShell module that integrates Git and PowerShell by providing _Git status summary informatio_n that can be displayed in the PowerShell prompt, e.g. โ€” posh-git also provides tab completion support for common git commands, branch names, paths and more. However, those who donโ€™t use Git can use only oh-my-gish for their customised terminal window for a lovely attractive working environment.

๐”๐๐ƒ๐€๐“๐„ :๐™’๐˜ผ๐™„๐™โœ‹โœ‹โœ‹โ€ฆ ๐™ค๐™-๐™ข๐™ฎ-๐™ฅ๐™ค๐™จ๐™ ๐™‘๐Ÿ‘ ๐™„๐™จ ๐™Š๐™ช๐™ฉ. ๐™‹๐™ก๐™š๐™–๐™จ๐™š ๐™๐™š๐™–๐™™ ๐™ˆ๐™ฎ ๐™‡๐™–๐™ฉ๐™š๐™จ๐™ฉ ๐˜ผ๐™ง๐™ฉ๐™ž๐™˜๐™ก๐™š ๐™ค๐™ฃ ๐™ฉ๐™๐™š ๐™ค๐™-๐™ข๐™ฎ-๐™ฅ๐™ค๐™จ๐™ ๐™ˆ๐™ค๐™™๐™ช๐™ก๐™š ๐™๐™จ๐™ž๐™ฃ๐™œ ๐™ฉ๐™๐™š ๐™๐™ค๐™ก๐™ก๐™ค๐™ฌ๐™ž๐™ฃ๐™œ ๐™‡๐™ž๐™ฃ๐™ . ๐™๐™๐™š๐™ฃ ๐˜พ๐™ค๐™ข๐™š ๐˜ฝ๐™–๐™˜๐™  ๐˜ผ๐™œ๐™–๐™ž๐™ฃ ๐™›๐™ค๐™ง ๐™๐™๐™š ๐™ฅ๐™ค๐™จ๐™-๐™œ๐™ž๐™ฉ ๐™‹๐™–๐™ง๐™ฉ.

โ• โ• โ•

Requirements

Basically, we donโ€™t need any extra type of tool for installing these modules. The only two requirements are โ€”

  • โ€ข Windows PowerShell
  • โ€ข Administrator Mode

Process

Step 1: Installation of modules:

This step is mainly divided into two parts, (1) Installation of oh-my-posh, (2) installation of posh-git. For both installations, Iโ€™m giving two possible methods using a simple line of command or manually. For beginners, Iโ€™ll recommend them for going with the command line procedure. Now, if you are not a programmer or donโ€™t use Git, then you donโ€™t need to install posh-git. If you use Git, then Iโ€™ll highly recommend you for installing posh-git.


(1) Installation of oh-my-posh:

For installing oh-my-posh one can type the following code in the PowerShell terminal window,

Install-Module oh-my-posh

One can also install it manually from the following URL,

https://github.com/JanDeDobbeleer/oh-my-posh

While installation computer can ask you permission for installing a higher version of NuGet. One can simply press enter (default selection is โ€œyesโ€) or can type โ€œyโ€ and then press enter. Then, one has to give another permission for installing modules from an untrusted repository. Donโ€™t worry, itโ€™ll not affect your computer. Simply type โ€œyโ€ and press enter for installation (please be sure here you have to write โ€œyโ€ as the default selection is โ€œnโ€ for this process)[Figure 1].

Installation of oh-my-posh

Figure 1: Installation of oh-my-posh
[2] Installation of posh-git:

For installing posh-git one has to type the following line of code in the PowerShell terminal window,

Install-Module posh-git

Another way of installation is a manual one. For that, one needs to use the following URL โ€”

https://github.com/dahlbyk/posh-git

For this installation also, one has to permit installing modules from an untrusted repository. Simply type โ€œyโ€ and press enter for installation (please be sure here you have to write โ€œyโ€ as the default selection is โ€œnโ€ for this process)[Figure 1.2].

Installation of posh-git

Figure 2: Installation of posh-git

Step 2: Setting some cool fonts:

Now, letโ€™s download some cool fonts for our PowerShell which windows supported. For that, one has to perform the following several steps โ€”

[1] Typing the following one-line command in the PowerShell terminal window,

Invoke-WebRequest -Uri 'https://github.com/powerline/fonts/archive/master.zip' -OutFile .\powerlinefonts.zip

[2] The above command downloads different fonts supported by Windows PowerShell in zip format. The next step is extracting the fonts from the zip file by typing the following command in the terminal โ€”

Expand-Archive .\powerlinefonts.zip

[3] Now we have to install all the fonts by using the following command โ€”

.\powerlinefonts\fonts-master\install.ps1

Now, probably youโ€™ll get an error like shown in Figure 3,

Probable error while installing custom fonts

Figure 3: Probable error while installing custom fonts

Now, one will have to tell the Execution Policy for moving forward. We will need to set to Execution Policy to Bypass, so that we may run this script. So, we have to type Set-ExecutionPolicy Bypass in the terminal and run the .\powerlinefonts\fonts-master\install.ps1 command again. Now, one will be able to see a window showing โ€˜Installing Fontsโ€™ [Figure 4] โ€”

A window showing fonts installation

Figure 4: A window showing fonts installation

[4] now we can clean up the downloaded zip file using two following commands โ€”

Remove-Item .\powerlinefonts.zip
Remove-Item .\powerlinefonts -Recurse

[5] The last step is setting the font for PowerShell. Right-click on the PowerShell window top-bar for more options, go to Properties and then to Font. Select any font from the available options and click OK [Figure 5].

Setting the font from PowerShell console
Figure 5: Setting the font from PowerShell console

Step 3: Importing modules and setting theme:

After setting the font, we have to import the two modules using the following commands โ€”

Import-Module oh-my-posh
Import-Module posh-git

As you are all set up, you can see all the themes using the get-theme command [Figure 6].

Getting all the available themes

Figure 6: Getting all the available themes

Now, you can set any theme as you like using the set-theme [theme-name] command like following,

set-theme Agnoster

But till now this theme is not set yet as permanent. For that, type the following two commands in the terminal โ€”

if (!(Test-Path -Path $PROFILE )) { New-Item -Type File -Path $PROFILE -Force }
notepad $PROFILE

Now, itโ€™ll open a notepad window. Please add these 3 lines to the file and save it.

Import-Module oh-my-posh
Import-Module posh-git
Set-Theme Agnoster

These will set the Agnoster theme permanently for Windows PowerShell.

Step 4: Setting execution policy to default:

After setting the theme successfully set your execution policy to default by using the following command โ€”

Set-ExecutionPolicy Default

โ• โ• โ•

Itโ€™s all set up. But if you want to set your background colour and also the other colours of the theme manually (other than colours provided by PowerShell), there is a secret procedure. For that, you have to download the Dracula Theme for PowerShell from here after doing all the previous steps. Unzip the folder, navigate to inside the folder ColoTool and run install.cmd. Now your terminal should look like Figure 7,

Terminal after running install.cmd

Figure 7: Terminal after running install.cmd

Now close the PowerShell window and start again. This time the PowerShell window should look like Figure 8 โ€”

PowerShell window after installing Dracula theme

Figure 8: PowerShell window after installing Dracula theme

If you want to set your colour, then do the necessary changes in RGB colour percentages in Dracula-ColorTool.itermcolors file situated inside the install folder under the ColorTool folder.

After setting your favourite colour, please again set the font as itโ€™ll be unset after installing the Dracula theme. Have fun with your customized PowerShell terminal.

Note

  • โ€ข All available fonts do not work properly in the terminal. Sometimes you can see unsupported signs (e.g. โ€” git sign etc.). If you encounter such type of error, please set a different font using trial and error method. Youโ€™ll be all set.
  • โ€ข You must do all the operations in Administrator Mode. Otherwise, youโ€™ll end up with thousands of errors.

References

โ• โ• โ•

Thank you for reading.

I hope you found this โ€œCustomize Your Windows PowerShell With oh-my-posh & posh-gitโ€ 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.