Skip to content

Instantly share code, notes, and snippets.

@DamianEdwards
Last active August 24, 2023 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DamianEdwards/6b6522fe9acb575e606ea4688d600425 to your computer and use it in GitHub Desktop.
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": " \ue77f {{ 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 (${env:ProgramFiles(x86)} -ne $null) {
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;
}
if ($host.Name -eq 'ConsoleHost')
{
Import-Module PSReadLine
}
Import-Module posh-git, PSColors, Terminal-Icons
# Visual Studio Developer PowerShell
$vsInstallPath = Get-VsInstallLocation
if ($vsInstallPath -ne $null) {
Import-Module "$vsInstallPath\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"
Enter-VsDevShell -SkipAutomaticLocation -InstallPath $vsinstallpath | Out-Null
}
# PowerShell parameter completion shim for the dotnet CLI
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()
}
oh-my-posh init pwsh --config "$PSScriptRoot\craver-vs.omp.json" | Invoke-Expression
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
}
@DamianEdwards
Copy link
Author

@jmelosegui
Copy link

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
Author

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

@DamianEdwards
Copy link
Author

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

@DamianEdwards
Copy link
Author

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

@DamianEdwards
Copy link
Author

Updated for deprecation of oh-my-posh PowerShell module

@DamianEdwards
Copy link
Author

image

@DamianEdwards
Copy link
Author

DamianEdwards commented Jul 13, 2023

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

image

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