Oh My Posh Terminal Setup 

Setting up your terminal with Oh My Posh can enhance your PowerShell experience. Here’s a step-by-step guide:

Method 1: oh-my-posh init

Step 0: Install windows Terminal

https://apps.microsoft.com/detail/9N0DX20HK701?hl=en-US&gl=US

Open it as Administrator and follow the steps below.

Step 1: Install OhMyPosh & default OhMyPosh theme

https://ohmyposh.dev/docs/installation/windows

Open a PowerShell prompt and run the following command:

winget install JanDeDobbeleer.OhMyPosh -s winget

Note: After installing the oh-my-posh module, restart the terminal. If you get error, you can set the execution policy to Unrestricted:

Get-ExecutionPolicy
Set-ExecutionPolicy -ExecutionPolicy Unrestricted

Step 2: Install Font to populate the Characters

https://ohmyposh.dev/docs/installation/fonts

oh-my-posh font install

Select the font you like to install from dropdown list. Famouse fonts: Hack, FiraCode, Meslo, Caskaydiacove Nerd Font

Alternatively, you can manually download the zip files of the font of your choise and install it.

https://www.nerdfonts.com/

Step 3: Configure your terminal/editor to use the installed font

Go to your Terminal Setting and select the installed font. Settings > Windows Powershell > Appearance >Font face >

https://ohmyposh.dev/docs/installation/fonts

Note: You can also configure the integrated Terminal for the Visual Studio & Visual Studio Code to use the newly installed Font.

Step 4: Configure your shell to use Oh My Posh

https://ohmyposh.dev/docs/installation/prompt

notepad $PROFILE    or   node $PROFILE
oh-my-posh init pwsh | Invoke-Expression

Step 5: Customize and configure which theme you want to use (Optional)

https://ohmyposh.dev/docs/installation/customize

You can initialize oh-my-posh for PowerShell with a specific configuration file (agnoster.omp.json) located at “C:\Users\User\poshThemes”. You can put on of the oh-my-posh themes or your own theme in this directory.

oh-my-posh init pwsh --config 'C:\Users\User\poshThemes\agnoster.omp.json' | Invoke-Expression

OR

oh-my-posh init pwsh --config 'https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/agnoster.omp.json' | Invoke-Expression

You can find the thems here: https://ohmyposh.dev/docs/themes

Click the theme you like, it will take you to github > Raw > then you can copy the configuration link as shown above and put it in the notepad $PROFILE.

Alternatively you can download this theme and put it in C:\Users\User\poshThemes and initialise it.

List of OhMyPosh themes:

Get-PoshThemes

https://ohmyposh.dev/docs/themes

or

https://github.com/JanDeDobbeleer/oh-my-posh/tree/main/themes

Example: Use the second instead of the first to configure your shell in step 4.
https://github.com/JanDeDobbeleer/oh-my-posh/blob/main/themes/agnoster.omp.json
https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/agnoster.omp.json

oh-my-posh init pwsh --config 'https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/agnoster.omp.json' | Invoke-Expression

Step 6: Install Terminal-Icons Module (Optional)

Terminal-Icons module is a PowerShell module to show file and folder icons in the terminal. It adds file and folder icons when displaying items in the terminal.

It gives files and folders the following look.

We install this module from the PowerShell Gallery:

Install-Module -Name Terminal-Icons -Repository PSGallery

PowerShell Gallery is the central repository for sharing and acquiring PowerShell code including PowerShell modules, scripts, and DSC resources.

https://github.com/devblackops/Terminal-Icons

Import-Module -Name Terminal-Icons

Step 7: Install PSReadLine for autocompletion (Optional)

First check installed modules

get-module

Update the PSReadLine if it already installed

Install-Module PSReadLine -Force

You can make the terminal autocompletion from history and show list view of commands as you type.

Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -PredictionViewStyle ListView
If you want to Uninstall oh-my-posh

Check this guide: http://wubishet.com/oh-my-posh-installing-and-uninstalling-with-winget/

Method 2: Import-Module and Set-PoshPrompt

Step 1: Install PowerShellGet (if not installed)

Install-Module -Name PowerShellGet -Force -AllowClobber

Step 2: Install Oh-My-Posh

Install-Module oh-my-posh -Scope CurrentUser

Step 3: Import Oh-My-Posh module and set a theme

Import-Module oh-my-posh

# Set the theme
Set-PoshPrompt -Theme Agnoster

Step 4: Verify Oh-My-Posh setup

Restart your PowerShell. You should now see the new prompt with the selected theme. You can further customize the prompt or explore different themes based on your preferences.

https://ohmyposh.dev/docs/themes

You can also explore other themes by checking the available themes in the Oh-My-Posh module. Run the following command to see the available themes:

Get-PoshThemes

Step 5: Install Oh-My-Posh Font

Run the command in your PowerShell session.

oh-my-posh font install

Select the font you want to install from the dropdown list. Common choices include Hack, FiraCode, Meslo, and Caskaydiacove Nerd Font.

Alternatively, you can manually download the zip files of the font of your choise and install it.

https://www.nerdfonts.com/

Step 6: Configure Your Terminal to use the installed Nerd Font

Go to your Terminal Setting and select the installed font. Settings > Windows Powershell > Appearance >Font face >

https://ohmyposh.dev/docs/installation/fonts

Note: You can also configure the integrated Terminal for the Visual Studio & Visual Studio Code to use the newly installed Font.

Step 7: Optionally, configure your PowerShell profile

If you want the Oh-My-Posh setup to be persistent across PowerShell sessions, you can add the import and theme-setting commands to your PowerShell profile. Open your profile script with:

notepad $PROFILE

Add the following lines at the end of the profile script:

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

Step 7: Restart PowerShell

Close and reopen your PowerShell session or run:

. $PROFILE

Step 8: Install Terminal-Icons Module

To install the module from the PowerShell Gallery:

Install-Module -Name Terminal-Icons -Repository PSGallery

https://github.com/devblackops/Terminal-Icons

Usage

Import-Module -Name Terminal-Icons

You can import Oh-My-Posh in your PowerShell profile along with the Terminal-Icons module.

Import-Module -Name Terminal-Icons
Import-Module -Name oh-my-posh

# Set the theme. You can choose a different theme if you prefer.
Set-PoshPrompt -Theme Agnoster
Additional Reading

Terminal-Icons Module

In PowerShell, when you import a module using Import-Module, it only affects the current session.

To make the module available in all future sessions, you can add the import command to your PowerShell profile. The profile is a script that runs when you start a new session. Here’s what you can do:

Open your PowerShell profile script. You can check if you already have a profile by running:

Test-Path $profile

If it returns False, you can create a profile script. Run the following to create a profile:

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

Open the profile script in your preferred text editor. You can use the following command:

notepad $profile

Add the Import-Module command to this script, like so:

Import-Module -Name Terminal-Icons

Save and close the profile script.

Now, every time you start a new PowerShell session, it will automatically import the Terminal-Icons module. This ensures that the module is available in all future sessions.

oh-my-posh Module

You can import Oh-My-Posh in your PowerShell profile along with the Terminal-Icons module.

Import-Module -Name Terminal-Icons
Import-Module -Name oh-my-posh

# Set the theme. You can choose a different theme if you prefer.
Set-PoshPrompt -Theme Agnoster

Oh-My-Posh is not a traditional PowerShell module that you can import using the Import-Module cmdlet. Instead, it’s a separate PowerShell module that provides prompt theming functionality for your PowerShell prompt.

To install Oh-My-Posh, you typically use a package manager for PowerShell like PowerShellGet.

# Install-Module -Name ModuleName
Install-Module -Name oh-my-posh -Scope CurrentUser

Check if PowerShellGet module is available:

Get-Module -ListAvailable -Name PowerShellGet

Check if the PackageManagement module is available

Get-Module -ListAvailable -Name PackageManagement

If you haven’t installed PowerShellGet yet, you can do so by running:

Install-Module -Name PowerShellGet -Force -AllowClobber

Future Readings

PowerShell Gallery:

https://www.powershellgallery.com/

If you find this post important, share to your friends