To install Oh-My-Posh for PowerShell, run the following command:
Install-Module oh-my-posh -Scope CurrentUser -Force -SkipPublisherCheckOh-My-Posh uses special fonts for the prompt. You can download and install Nerd Fonts from the official website: Nerd Fonts.
### Step 1: List all releases to get the latest tag
You can use the `gh release list` command to get a list of releases and find the latest tag:
gh release list --repo ryanoasis/nerd-fonts
This will give you a list of releases like:
v3.4.0 v2.0.0 v1.9.0 ....
The first entry (`v3.4.0`, for example) is the latest release.
### Step 2: Download the latest release
Now that you know the latest release tag (e.g., `v3.4.0`), you can use it with the `gh release download` command:
gh release download v3.4.0 --repo ryanoasis/nerd-fonts --dir nerd-fonts-latest
This will download the assets from the release `v3.4.0` and place them in the directory `nerd-fonts-latest`.
-
List the releases:
gh release list --repo ryanoasis/nerd-fonts -
Download the latest release (replace
v3.4.0with the actual tag):gh release download v3.4.0 --repo ryanoasis/nerd-fonts --dir nerd-fonts-latest
After installing the font, ensure to change the terminal font to one of the Nerd Fonts in your PowerShell profile.
To use a theme, you can choose from the built-in themes. First, list available themes:
Get-ChildItem (Join-Path (Get-Module oh-my-posh).ModuleBase 'themes') To make the theme persistent across sessions, edit your PowerShell profile ($PROFILE) by running:
notepad.exe $PROFILEAdd the following line to set the theme:
Set-PoshPrompt -Theme paradoxReplace paradox with your desired theme (e.g., agnoster, powerline, etc.).
To enable autocompletion for Oh-My-Posh, use the provided script from your original input. It should already be in your profile, but if not, add this block:
# powershell completion for oh-my-posh -*- shell-script -*-
function __oh-my-posh_debug {
if ($env:BASH_COMP_DEBUG_FILE) {
"$args" | Out-File -Append -FilePath "$env:BASH_COMP_DEBUG_FILE"
}
}
# Rest of your script here...Ensure this is included for autocompletion to work. This will allow you to use autocompletion in PowerShell when working with Oh-My-Posh themes.
You can create an interactive alias or script to list all themes and allow you to choose one by entering a number. Here’s how:
Create a script named Select-PoshTheme.ps1 and add it to your $PROFILE or a script folder.
# Select-PoshTheme.ps1 - Interactive theme selector for Oh-My-Posh
function Select-PoshTheme {
$themes = Get-ChildItem (Join-Path (Get-Module oh-my-posh).ModuleBase 'themes')
$themeNames = $themes | ForEach-Object { $_.Name }
$i = 1
$themeNames | ForEach-Object {
Write-Host "$i) $_"
$i++
}
$choice = Read-Host "Enter the number of the theme you'd like to use"
if ($choice -gt 0 -and $choice -le $themeNames.Length) {
$selectedTheme = $themeNames[$choice - 1]
Write-Host "Setting theme: $selectedTheme"
Set-PoshPrompt -Theme $selectedTheme
} else {
Write-Host "Invalid choice. Please enter a valid number."
}
}
# Create an alias for easy access
Set-Alias SelectTheme Select-PoshThemeAfter creating the Select-PoshTheme.ps1 script, you can add it to your $PROFILE for easy access. To do so, open your PowerShell profile:
notepad.exe $PROFILEThen add this line at the end of your profile to ensure the script is loaded automatically:
. "C:\path\to\Select-PoshTheme.ps1"Replace "C:\path\to\Select-PoshTheme.ps1" with the actual path to the script.
PowerShell’s PSReadLine module provides autocompletion for commands and history. If PSReadLine is not installed, install it with:
Install-Module PSReadLine -Force -SkipPublisherCheckEnable PSReadLine and configure history features by adding the following to your $PROFILE:
# Enable PSReadLine
Import-Module PSReadLine
# Enable history search using the Up and Down keys
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
# Enable color and syntax highlighting
$Global:PSReadLineOptions = @{
HistorySearchCursor = "green"
PromptBackgroundColor = "Black"
PromptForegroundColor = "White"
}
# Optional: Set the history file
$env:PSReadlineHistoryFile = "$env:USERPROFILE\Documents\PowerShell_history.txt"To apply the changes and reload your profile:
. $PROFILENow, you can use the SelectTheme alias to list all available themes and choose one interactively:
SelectThemeEnter the number corresponding to the theme you want to select, and the script will change the theme for you.
- Install Oh-My-Posh using
Install-Module. - Install Nerd Fonts to properly display the prompt.
- Set a theme in your
$PROFILE. - Enable autocompletion with the provided script.
- Create an interactive theme selector script to pick a theme by number.
- Enable PSReadLine for command history and search features.
This setup provides a full Oh-My-Posh experience with themes, autocompletion, and command history in PowerShell.
# Define all available Nerd Fonts
$fonts = @(
'0xProto', '3270', 'Agave', 'AnonymousPro', 'Arimo', 'AurulentSansMono',
'BigBlueTerminal', 'BitstreamVeraSansMono', 'CascadiaCode', 'CodeNewRoman',
'ComicShannsMono', 'Cousine', 'DaddyTimeMono', 'DejaVuSansMono',
'DroidSansMono', 'EnvyCodeR', 'FantasqueSansMono', 'FiraCode', 'FiraMono',
'Go-Mono', 'Gohu', 'Hack', 'Hasklig', 'HeavyData', 'Hermit', 'iA-Writer',
'IBMPlexMono', 'Inconsolata', 'InconsolataGo', 'InconsolataLGC', 'Iosevka',
'IosevkaTerm', 'JetBrainsMono', 'Lekton', 'LiberationMono', 'Lilex',
'Meslo', 'Monofur', 'Monoid', 'Mononoki', 'MPlus', 'NerdFontsSymbolsOnly',
'Noto', 'OpenDyslexic', 'Overpass', 'ProFont', 'ProggyClean', 'RobotoMono',
'ShareTechMono', 'SourceCodePro', 'SpaceMono', 'Terminus', 'Tinos',
'Ubuntu', 'UbuntuMono', 'VictorMono'
)
# Create necessary directories
$downloadPath = "$env:TEMP\NerdFonts"
$extractPath = "$downloadPath\extracted"
New-Item -ItemType Directory -Force -Path $downloadPath | Out-Null
New-Item -ItemType Directory -Force -Path $extractPath | Out-Null
# Download and install each font
foreach ($font in $fonts) {
Write-Host "`nProcessing $font..." -ForegroundColor Cyan
# Download
try {
Write-Host "Downloading $font..."
$url = "https://github.com/ryanoasis/nerd-fonts/releases/latest/download/$font.zip"
Invoke-WebRequest -Uri $url -OutFile "$downloadPath$font.zip" -UseBasicParsing
# Extract
Write-Host "Extracting $font..."
Expand-Archive -Path "$downloadPath$font.zip" -DestinationPath "$extractPath$font" -Force
# Install
Write-Host "Installing $font fonts..."
Get-ChildItem -Path "$extractPath$font" -Include "*.ttf","*.otf" -Recurse | ForEach-Object {
$fontFile = $_.FullName
$destFile = Join-Path "$env:WINDIR\Fonts" $_.Name
Copy-Item -Path $fontFile -Destination $destFile -Force
Write-Host "Installed $($_.Name)" -ForegroundColor Green
}
# Cleanup zip file
Remove-Item "$downloadPath$font.zip" -Force
}
catch {
Write-Host "Failed to process $($font): $($_.Exception.Message)" -ForegroundColor Red
}
}
# Final cleanup
Write-Host "`nCleaning up temporary files..." -ForegroundColor Cyan
Remove-Item -Path $downloadPath -Recurse -Force
Write-Host "`nInstallation completed!" -ForegroundColor Green
oh-my-posh font install '0xProto'
oh-my-posh font install 3270
oh-my-posh font install AdwaitaMono
oh-my-posh font install Agave
oh-my-posh font install AnonymousPro
oh-my-posh font install Arimo
oh-my-posh font install AtkinsonHyperlegibleMono
oh-my-posh font install AurulentSansMono
oh-my-posh font install BigBlueTerminal
oh-my-posh font install BitstreamVeraSansMono
oh-my-posh font install CascadiaCode
oh-my-posh font install 'CascadiaCode(MS)'
oh-my-posh font install CascadiaMono
oh-my-posh font install CodeNewRoman
oh-my-posh font install ComicShannsMono
oh-my-posh font install CommitMono
oh-my-posh font install Cousine
oh-my-posh font install D2Coding
oh-my-posh font install DaddyTimeMono
oh-my-posh font install DejaVuSansMono
oh-my-posh font install DepartureMono
oh-my-posh font install DroidSansMono
oh-my-posh font install EnvyCodeR
oh-my-posh font install FantasqueSansMono
oh-my-posh font install FiraCode
oh-my-posh font install FiraMono
oh-my-posh font install FontPatcher
oh-my-posh font install GeistMono
oh-my-posh font install Go-Mono
oh-my-posh font install Gohu
oh-my-posh font install Hack
oh-my-posh font install Hasklig
oh-my-posh font install HeavyData
oh-my-posh font install Hermit
oh-my-posh font install IBMPlexMono
oh-my-posh font install Inconsolata
oh-my-posh font install InconsolataGo
oh-my-posh font install InconsolataLGC
oh-my-posh font install IntelOneMono
oh-my-posh font install Iosevka
oh-my-posh font install IosevkaTerm
oh-my-posh font install IosevkaTermSlab
oh-my-posh font install JetBrainsMono
oh-my-posh font install Lekton
oh-my-posh font install LiberationMono
oh-my-posh font install Lilex
oh-my-posh font install MPlus
oh-my-posh font install MartianMono
oh-my-posh font install Meslo
oh-my-posh font install Monaspace
oh-my-posh font install Monofur
oh-my-posh font install Monoid
oh-my-posh font install Mononoki
oh-my-posh font install NerdFontsSymbolsOnly
oh-my-posh font install Noto
oh-my-posh font install OpenDyslexic
oh-my-posh font install Overpass
oh-my-posh font install ProFont
oh-my-posh font install ProggyClean
oh-my-posh font install Recursive
oh-my-posh font install RobotoMono
oh-my-posh font install ShareTechMono
oh-my-posh font install SourceCodePro
oh-my-posh font install SpaceMono
oh-my-posh font install Terminus
oh-my-posh font install Tinos
oh-my-posh font install Ubuntu
oh-my-posh font install UbuntuMono
oh-my-posh font install UbuntuSans
oh-my-posh font install VictorMono
oh-my-posh font install ZedMono
oh-my-posh font install iA-Writer