Language: EN

oh-my-post

How to customize Windows Terminal with Oh My Posh

Today we are going to see how to configure the new Windows Terminal to get the most out of this interesting Microsoft command console.

In the previous post, we saw what the new Windows Terminal is, and how it incorporated significant functional and aesthetic improvements over the previous console application.

Now let’s configure it, for which we will use its customization capability by including additional modules.

Install font for developers

The first thing we must do to configure the terminal of Windows is to install a font specially designed for developers, suitable for displaying code fragments.

These types of fonts include fonts specially prepared to be especially readable. They also include other interesting features such as icons, ligatures, or adequate spacing.

We can download developer fonts from the page https://www.nerdfonts.com/. Personally, I like the Incosolata font (model with Windows Compatibility), but use the one that suits your preferences.

Install Oh My Posh

Next, we are going to install PowerLine, which allows us to improve the appearance of the current console line. It is a popular plugin, available in many terminal developments.

windows-terminal-git

To install it in PowerShell we will use Oh-My-Posh, for which we run the following command,

winget install JanDeDobbeleer.OhMyPosh -s winget

Next, we must configure Oh-My-Posh, editing the file $profile. If this is the first time we edit it, we will have to create it previously by executing,

New-Item -Path $PROFILE -Type File -Force

Once created, we can edit it with notepad (or any other text editor) by doing,

notepad $PROFILE

In the $profile file we must add this line, which simply starts Oh-MyPosh when PowerShell starts.

oh-my-posh init pwsh | Invoke-Expression

Finally, we make the changes in the profile effective by executing the following command,

. $PROFILE

Customize Oh-My-Post appearance

Next, we have to select one of the available Themes. For that, first we run the following command to list all the Themes,

Get-PoshThemes

We can select one of these predefined Themes, or create or create our own Theme. If we want to create our own Theme, we would go to the themes folder, located in the following environment variable

%POSH_THEMES_PATH%

There, we would create a JSON file containing the configuration of our Theme. However, it will be normal to work based on one of the existing Jsons and modify it to our liking, instead of starting from scratch.

In either case, whether with one of the predefined Themes or with our own Theme, we must modify the configuration file to indicate that it loads the Theme during the startup of PowerShell.

To do this, we edit the $profile file again, replacing the line we put with this one

oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH/default.json" | Invoke-Expression

Where ‘default.json’ is the name of the Theme we want to apply.

Install Git module

Another interesting improvement that we can include in our Windows Terminal is to add Git compatibility to the PowerLine. To do this, we would install the posh-git module using the following command

Install-Module posh-git -Scope CurrentUser

Now we must load this module at startup. To do this, we include it in our $profile in the same way we did with Oh-My-Posh, adding the following line to the end of the file

Import-Module posh-git

Install icons for files and folders

Finally, another interesting module that we can do to customize our Windows terminal is to add the Terminal-Icons module, which adds icons to files and folders. First we install it with the following command,

Install-Module -Name Terminal-Icons -Repository PSGallery

As in the previous cases, we will have to add it to our $profile configuration file, including the following line

Install-Module -Name Terminal-Icons -Repository PSGallery
Import-Module -Name Terminal-Icons

References