This snippet stores my current PowerShell setup, consisting of posh-git
, Terminal-Icons
, ZLocation
, oh-my-posh
and PSReadLine
.
Also, I use a customized oh-my-posh theme that I am still fiddling with (see below).
To properly render all glyphs, I use the Caskaydia Cove Nerd Font, a Nerd-Font-variant of Cacadia Code (which I use in the VS and VS Code editors), inside of Windows Terminal.
I use the CurrentUserAllHosts profile, which you can find at $PROFILE.CurrentUserAllHosts
.
If available, I install the modules via winget or Chocolatey, otherwise via the PowerShell gallery.
# Put this in Microsoft.PowerShell_profile.ps1 ($PROFILE.CurrentUserAllHosts)
# Posh-Git displays git information within the terminal
Import-Module posh-git
# Terminal-Icons shows file and folder icons
Import-Module Terminal-Icons
# ZLocation allows for quick navigation
Import-Module ZLocation
# Oh-My-Posh was installed via winget
# The customized theme was put next to the profile
$ohMyPoshThemeConfigPath = "$($PROFILE.CurrentUserAllHosts)\..\custom-theme-tnv.omp.json"
oh-my-posh --init --shell pwsh --config $ohMyPoshThemeConfigPath | Invoke-Expression
Enable-PoshTooltips
if ($host.Name -eq 'ConsoleHost') {
# PSReadLine improves shortcut handling
Import-Module PSReadLine
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
}
Then put this in a file named custom-theme-tnv.omp.json
next to the profile:
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"blocks": [{
"alignment": "left",
"segments": [{
"background": "#000000",
"foreground": "#dd1e1e",
"properties": {
"template": " \u26a1"
},
"style": "plain",
"type": "root"
},
{
"background": "#000000",
"foreground": "#ffffff",
"properties": {
"alpine": "\uf300",
"arch": "\uf303",
"centos": "\uf304",
"debian": "\uf306",
"elementary": "\uf309",
"fedora": "\uf30a",
"gentoo": "\uf30d",
"linux": "\ue712",
"macos": "\ue711",
"manjaro": "\uf312",
"mint": "\uf30f",
"opensuse": "\uf314",
"raspbian": "\uf315",
"template": " {{ if .WSL }}WSL at {{ end }}{{.Icon}} ",
"ubuntu": "\uf31c",
"windows": "",
"wsl": "\ue712"
},
"style": "plain",
"type": "os"
},
{
"background": "#4d4d4d",
"foreground": "#43CCEA",
"properties": {
"folder_icon": "\ue5fe",
"folder_separator_icon": "<transparent> \ue0bd </>",
"home_icon": "\uf7db",
"style": "agnoster_short",
"template": " {{ .Path }} "
},
"style": "plain",
"type": "path"
},
{
"background": "#4d4d4d",
"foreground": "#00ff0d",
"properties": {
"fetch_stash_count": true,
"fetch_status": true,
"template": "<#000000>\ue0b1 </>{{ .HEAD }}{{ if .Staging.Changed }}<#FF6F00> \uf046 {{ .Staging.String }}</>{{ end }}{{ if and (.Working.Changed) (.Staging.Changed) }} |{{ end }}{{ if .Working.Changed }} \uf044 {{ .Working.String }}{{ end }}{{ if gt .StashCount 0 }} \uf692 {{ .StashCount }}{{ end }} "
},
"style": "plain",
"type": "git"
},
{
"background": "#4d4d4d",
"foreground": "#ffffff",
"properties": {
"style": "dallas",
"template": "<#000000>\ue0b1 </>{{ .FormattedMs }}s ",
"threshold": 0
},
"style": "diamond",
"trailing_diamond": "\ue0b0",
"type": "executiontime"
}
],
"type": "prompt"
},
{
"alignment": "right",
"segments": [{
"background": "#4d4d4d",
"foreground": "#43CCEA",
"leading_diamond": "\ue0b2",
"properties": {
"template": " {{ if .SSHSession }}\uf817 {{ end }}{{ .UserName }}<#43CCEA>@</>{{ .HostName }}"
},
"style": "diamond",
"type": "session"
},
{
"background": "#4d4d4d",
"foreground": "#43CCEA",
"properties": {
"template": "<#000000> </>{{ .CurrentDate | date .Format }} ",
"time_format": "15:04:05"
},
"style": "diamond",
"trailing_diamond": "",
"type": "time"
}
],
"type": "prompt"
},
{
"alignment": "left",
"newline": true,
"segments": [{
"foreground": "#00ff0d",
"foreground_templates": [
"{{ if gt .Code 0 }}#ff0000{{ end }}"
],
"properties": {
"always_enabled": true,
"template": "\u276f "
},
"style": "plain",
"type": "exit"
}],
"type": "prompt"
}
],
"final_space": true,
"osc99": true,
"version": 1,
"console_title": true,
"console_title_style": "template",
"console_title_template": "{{ .Shell }} in {{ .Folder }}",
"tooltips": [{
"type": "angular",
"tips": ["ng"],
"style": "diamond",
"foreground": "#000000",
"background": "#1976d2",
"leading_diamond": "\ue0b2",
"trailing_diamond": "",
"properties": {
"template": " \uE753 {{ .Full }} "
}
},
{
"type": "az",
"tips": ["az"],
"style": "diamond",
"foreground": "#000000",
"background": "#9ec3f0",
"leading_diamond": "\ue0b2",
"trailing_diamond": "",
"properties": {
"template": " \uFD03 {{ .Name }}"
}
}
]
}