Customize Your Windows PowerShell With oh-my-posh & posh-git

·

7 min read

Customize Your Windows PowerShell With oh-my-posh & posh-git

Image for post

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 which 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 information 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</span>

One can also install it manually from the following URL,

https://github.com/JanDeDobbeleer/oh-my-posh</span>

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

Image for post

[Installation of oh-my-posh (fig. — 1.1)]

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</span>

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

https://github.com/dahlbyk/posh-git</span>

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

Image for post

[Installation of posh-git (fig. — 1.2)]

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 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</span>

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</span>

3. Now we have to install all the fonts by using the following command —

.\powerlinefonts\fonts-master\install.ps1</span>

Now, probably you’ll get an error like shown in fig.-1.3,

Image for post

[Probable error while installing custom fonts (fig. — 1.3)]

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’ [fig.-1.4] —

Image for post

[A window showing fonts installation (fig. -1.4)]

4. now we can clean up the downloaded zip file using two following commands —

Remove-Item .\powerlinefonts -Recurse</span>

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 [fig.-1.5].

Image for post

[Setting the font from PowerShell console (fig. — 1.5)]

Step 3: Importing modules and setting theme: After setting the font, we have to import the two modules using the following commands —

Import-Module posh-git</span>

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

Image for post

[Getting all the available themes (fig. — 1.6)]

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

set-theme Agnoster</span>
  • But till now this theme is not set yet as permanent. For that, type following two commands in the terminal —
notepad $PROFILE</span>

Now, it’ll open a notepad window. Please add these 3 lines in the file and save it.

Import-Module oh-my-posh
Import-Module posh-git
Set-Theme Agnoster</span>

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_</span>

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 hereafter doing all the previous steps. Unzip the folder, navigate to inside the folder ColoTool and run install.cmd. Now your terminal should look like fig.-1.7,

Image for post

[Terminal after running install.cmd (fig. — 1.7)]

Now close the PowerShell window and start again. This time the PowerShell window should look like fig.-1.8 —

Image for post

[PowerShell window after installing Dracula theme (fig. — 1.8)]

If you want to set your colour, then do necessary changes in RGB colour percentages in Dracula-ColorTool.itermcolors file situated inside the install folder under 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’ helpful. Please clap, share and follow if you like and please leave any comment to let me know your thoughts.

Follow Me:

GitHubgithub.com/aritraroy24

LinkedInlinkedin.com/in/aritraroy24