Skip to content

Instantly share code, notes, and snippets.

@DamianEdwards
Last active March 21, 2026 17:07
Show Gist options
  • Select an option

  • Save DamianEdwards/6b6522fe9acb575e606ea4688d600425 to your computer and use it in GitHub Desktop.

Select an option

Save DamianEdwards/6b6522fe9acb575e606ea4688d600425 to your computer and use it in GitHub Desktop.
PowerShell Profile & oh-my-posh theme
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"version": 2,
"console_title_template": "{{if .Root}}(Admin) {{end}}{{.Folder}}",
"blocks": [
{
"type": "prompt",
"alignment": "left",
"segments": [
{
"type": "root",
"style": "plain",
"foreground": "#f1184c",
"template": " \uf0e7 "
},
{
"type": "os",
"style": "plain",
"foreground": "#3A86FF",
"template": "{{ if .WSL }}WSL at {{ end }}{{.Icon}} "
},
{
"type": "time",
"style": "plain",
"foreground": "#FFBB00",
"template": " {{ .CurrentDate | date .Format }} ",
"properties": {
"time_format": "15:04:05"
}
},
{
"type": "text",
"style": "powerline",
"powerline_symbol": "\ue0c4",
"foreground": "#ffffff",
"background": "#5C2D91",
"template": "{{if .Env.VSCMD_VER}} \udb81\ude10 {{.Env.VSCMD_VER}} {{ end }}"
},
{
"type": "path",
"style": "plain",
"foreground": "#33DD2D",
"template": " \ue5ff {{ .Path }} ",
"properties": {
"folder_separator_icon": "/",
"style": "agnoster_short"
}
},
{
"type": "git",
"style": "plain",
"foreground": "#3A86FF",
"template": "{{ .HEAD }} {{ .BranchStatus }}{{ if .Working.Changed }} \uf044 {{ .Working.String }}{{ end }}{{ if and (.Staging.Changed) (.Working.Changed) }} |{{ end }}{{ if .Staging.Changed }} \uf046 {{ .Staging.String }}{{ end }}{{ if gt .StashCount 0}} \uf0c7 {{ .StashCount }}{{ end }}{{ if gt .WorktreeCount 0}} \uf1bb {{ .WorktreeCount }}{{ end }}",
"properties": {
"fetch_stash_count": true,
"fetch_status": true,
"fetch_upstream_icon": true
}
},
{
"type": "dotnet",
"style": "powerline",
"powerline_symbol": "\ue0c4",
"foreground": "#ffffff",
"background": "#512BD4",
"template": " \udb82\udeae {{ if .Unsupported }}\uf071{{ else }}{{ .Full }}{{ end }} "
},
{
"type": "executiontime",
"style": "powerline",
"powerline_symbol": "\ue0c4",
"foreground": "#ffffff",
"background": "#0184bc",
"template": " <#fefefe>\uf520</> {{ .FormattedMs }} ",
"properties": {
"style": "austin",
"threshold": 1
}
},
{
"type": "exit",
"style": "powerline",
"powerline_symbol": "\ue0c4",
"foreground": "#242424",
"background": "#33DD2D",
"background_templates": [
"{{ if gt .Code 0 }}#f1184c{{ end }}"
],
"template": " \udb82\udfea "
}
]
},
{
"type": "prompt",
"alignment": "left",
"segments": [
{
"type": "text",
"style": "plain",
"foreground": "#f1184c",
"template": "➜ "
}
],
"newline": true
}
]
}
function Get-ProgramFiles32() {
if ($null -ne ${env:ProgramFiles(x86)}) {
return ${env:ProgramFiles(x86)}
}
return $env:ProgramFiles
}
function Get-VsInstallLocation() {
$programFiles = Get-ProgramFiles32
$vswhere = "$programFiles\Microsoft Visual Studio\Installer\vswhere.exe"
if (Test-Path $vswhere) {
$vsinstallpath = (. "$vswhere" -latest -prerelease -property installationPath -format value -nologo | Out-String).Trim()
return $vsinstallpath
}
return $null;
}
# Visual Studio Developer PowerShell
function Enable-VsShell() {
$vsInstallPath = Get-VsInstallLocation
if ($null -ne $vsInstallPath) {
Import-Module "$vsInstallPath\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"
Enter-VsDevShell -SkipAutomaticLocation -InstallPath $vsinstallpath | Out-Null
}
else {
Write-Host "Visual Studio not found"
}
}
if ($host.Name -eq 'ConsoleHost') {
Import-Module PSReadLine
[console]::InputEncoding = [console]::OutputEncoding = [System.Text.UTF8Encoding]::new()
}
Import-Module posh-git, PSColors, Terminal-Icons
# PowerShell parameter completion shim for the dotnet CLI
$dotnetPath = Get-Command dotnet -ErrorAction SilentlyContinue
if (!($null -eq $dotnetPath)) {
$dotnetVersion = dotnet --version
if ($dotnetVersion.StartsWith('10.0.100')) {
# .NET 10
(dotnet completions script pwsh) | Out-String | Invoke-Expression -ErrorAction SilentlyContinue
}
else {
# .NET <10
Register-ArgumentCompleter -Native -CommandName dotnet -ScriptBlock {
param($commandName, $wordToComplete, $cursorPosition)
dotnet complete --position $cursorPosition "$wordToComplete" | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}
}
}
# This is an example of a macro that you might use to execute a command.
# This will add the command to history.
# Set-PSReadLineKeyHandler -Key Ctrl+Shift+b `
# -BriefDescription BuildCurrentDirectory `
# -LongDescription "Build the current directory" `
# -ScriptBlock {
# [Microsoft.PowerShell.PSConsoleReadLine]::RevertLine()
# [Microsoft.PowerShell.PSConsoleReadLine]::Insert("dotnet build")
# [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine()
# }
Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete
# Enable UTF-8 in the console
[console]::InputEncoding = [console]::OutputEncoding = [System.Text.UTF8Encoding]::new()
# Initialize oh-my-posh
$ohmyposhProfile = "$PSScriptRoot\craver-vs.omp.json"
if (Test-Path D:\src\craver-vs.omp.json) {
$ohmyposhProfile = "D:\src\craver-vs.omp.json"
}
oh-my-posh init pwsh --config "$ohmyposhProfile" | Invoke-Expression
# Alias bombbardier
if (Test-Path C:\tools\bombardier-windows-amd64.exe) {
Set-Alias bomb C:\tools\bombardier-windows-amd64.exe
}
elseif (Test-Path D:\tools\bombardier-windows-amd64.exe) {
Set-Alias bomb D:\tools\bombardier-windows-amd64.exe
}
# Remove the 'where' alias
Remove-Item alias:\where -Force -ErrorAction SilentlyContinue
@DamianEdwards

Copy link
Copy Markdown
Author

@jmelosegui

Copy link
Copy Markdown

Thanks for sharing this.

Have you tried to use envvar blocks?

{
  "type": "envvar",          
  "style": "powerline",
  "powerline_symbol": "\uE0C4",
  "foreground": "#ffffff",
  "background": "#5C2D91",
  "properties": {
    "prefix": " ﬏ ",            
    "var_name": "VSCMD_VER"
  }
}

@DamianEdwards

Copy link
Copy Markdown
Author

@jmelosegui I haven't! Will that block be hidden if the envvar is empty?

@DamianEdwards

Copy link
Copy Markdown
Author

Seems it will, giving it a try now...

@DamianEdwards

Copy link
Copy Markdown
Author

@jmelosegui thanks for that, I've updated it to use the envvar block now 👍

@DamianEdwards

Copy link
Copy Markdown
Author

Updated for deprecation of oh-my-posh PowerShell module

@DamianEdwards

Copy link
Copy Markdown
Author

image

@DamianEdwards

DamianEdwards commented Jul 13, 2023

Copy link
Copy Markdown
Author

Updated for latest oh-my-posh & NerdFonts v3.0.0+

image

@DamianEdwards

Copy link
Copy Markdown
Author

Added line to end of PowerShell profile that removes the where alias so that you can just type where blah, etc. to find where blah is.

@DamianEdwards

Copy link
Copy Markdown
Author

Updated PowerShell profile for .NET 10 SDK completion provider.

@DamianEdwards

DamianEdwards commented May 6, 2025

Copy link
Copy Markdown
Author

Updated oh-my-posh config to use new .NET icon
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment