Skip to content

Instantly share code, notes, and snippets.

@LindnerBrewery
Last active October 2, 2023 10:04
Show Gist options
  • Save LindnerBrewery/bed217b6b9dd59696a2b732a3c918d2d to your computer and use it in GitHub Desktop.
Save LindnerBrewery/bed217b6b9dd59696a2b732a3c918d2d to your computer and use it in GitHub Desktop.
Oh-My-Posh
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"version": 2,
"final_space": true,
"console_title_template": "{{if .Root}}root {{end}}{{ .Shell }} in {{ .Folder }}",
"blocks": [
{
"type": "prompt",
"alignment": "left",
"segments": [
{
"type": "os",
"style": "diamond",
"powerline_symbol": "\ue0b0",
"foreground": "#ffffff",
"foreground_templates": [
"{{if .Root}}#000000{{end}}"
],
"background": "#16b13f",
"background_templates": [
"{{if .Root}}#ffff66{{end}}"
],
"leading_diamond": "\ue0b6",
"template": "{{ if .WSL }}WSL at {{ end }}{{.Icon}} "
},
{
"type": "session",
"style": "powerline",
"powerline_symbol": "\ue0b0",
"foreground": "#ffffff",
"background": "#0530a5",
"template": "{{ .UserName }}@{{ .HostName }}"
},
{
"type": "path",
"style": "powerline",
"powerline_symbol": "\ue0b0",
"foreground": "#ffffff",
"background": "#db7d1f",
"template": " \ue613 {{ .Path }} ",
"properties": {
"folder_icon": "..",
"home_icon": "~",
"mapped_locations": {
"C:\\GIT": "\uf1d3 ",
"C:\\Users\\emrys.macinally\\GIT": "\uf1d3 "
},
"mapped_locations_enabled": true,
"mixed_threshold": 4,
"style": "mixed"
}
},
{
"type": "git",
"style": "powerline",
"powerline_symbol": "",
"foreground": "#193549",
"background": "#ffeb3b",
"background_templates": [
"{{ if or (.Working.Changed) (.Staging.Changed) }}#FFEB3B{{ end }}",
"{{ if and (gt .Ahead 0) (gt .Behind 0) }}#FFCC80{{ end }}",
"{{ if gt .Ahead 0 }}#B388FF{{ end }}",
"{{ if gt .Behind 0 }}#B388FB{{ end }}"
],
"template": "{{ .UpstreamIcon }}{{ .HEAD }}{{if .BranchStatus }} {{ .BranchStatus }}{{ end }}{{ if .Working.Changed }}  {{ .Working.String }}{{ end }}{{ if and (.Working.Changed) (.Staging.Changed) }} |{{ end }}{{ if .Staging.Changed }}  {{ .Staging.String }}{{ end }}{{ if gt .StashCount 0 }}  {{ .StashCount }}{{ end }}",
"properties": {
"fetch_status": true,
"fetch_stash_count": true,
"fetch_upstream_icon": true,
"untracked_modes": {
"/Users/user/Projects/oh-my-posh/": "no"
}
}
},
{
"type": "executiontime",
"style": "powerline",
"powerline_symbol": "\ue0b0",
"foreground": "#ffffff",
"background": "#83769c",
"template": "<#ffff66>\ue384 </>{{ .FormattedMs }}",
"properties": {
"always_enabled": true
}
},
{
"type": "exit",
"style": "diamond",
"foreground": "#ffffff",
"background": "#00897b",
"background_templates": [
"{{ if gt .Code 0 }}#e91e63{{ end }}"
],
"trailing_diamond": "\ue0b4",
"template": "{{if .Env.doesnotexists}}\ue23a{{end}} ",
"properties": {
"always_enabled": true
}
}
]
},
{
"type": "prompt",
"alignment": "right",
"segments": [
{
"type": "ytm",
"style": "powerline",
"powerline_symbol": "\ue0b2",
"invert_powerline": true,
"foreground": "#111111",
"background": "#1BD760",
"template": " \uf167 {{ .Icon }}{{ if ne .Status \"stopped\" }}{{ .Artist }} - {{ .Track }}{{ end }} ",
"properties": {
"paused_icon": "\uf04c ",
"playing_icon": "\uf04b "
}
},
{
"type": "spotify",
"style": "powerline",
"powerline_symbol": "\ue0b2",
"invert_powerline": true,
"foreground": "#ffffff",
"background": "#1BD760",
"properties": {
"paused_icon": "\udb80\udfe4 ",
"playing_icon": "\ue602 ",
"stopped_icon": "\uf04d "
}
},
{
"type": "time",
"style": "diamond",
"invert_powerline": true,
"foreground": "#111111",
"background": "#2e9599",
"leading_diamond": "\ue0b2",
"trailing_diamond": "\ue0b4",
"template": " {{ .CurrentDate | date .Format }} "
}
]
},
{
"type": "prompt",
"alignment": "left",
"segments": [
{
"type": "shell",
"style": "powerline",
"foreground": "#ffffff",
"background": "#0077c2",
"template": "<#0077c2,transparent>\ue0b6</>\uf489{{ if and (eq .Shell \"pwsh\") (lt .ShellVersion \"6\") }} PS5.1 {{ else }} {{ .Shell }} {{ end }}<#0077c2,transparent>\ue0b4</>"
},
{
"type": "exit",
"style": "plain",
"foreground": "#007ACC",
"foreground_templates": [
"{{ if gt .Code 0 }}#e91e63{{ end }}"
],
"background": "transparent",
"template": " ❯ ",
"properties": {
"always_enabled": true
}
}
],
"newline": true
}
]
}
# check if fonts are installed
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
$installedFonts = (New-Object System.Drawing.Text.InstalledFontCollection).Families
if ($installedFonts -notcontains 'CaskaydiaCove Nerd Font'){
# download and install nerd font meslo
#$url = "https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/Meslo.zip" # MesloLGL Nerd Font
$url = "https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/CascadiaCode.zip" # CaskaydiaCove Nerd Font
$OutFolder = $env:TMP
$outFileName = ($url -split "/")[-1]
$outFile = Join-Path $OutFolder $outFileName
#download font
$wc = [System.Net.WebClient]::new()
$wc.DownloadFile($url,$outFile)
# unzip
$unzipFolder = $outFile.trim(".zip")
[Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem')
$zipFile = [IO.Compression.ZipFile]::OpenRead($outFile)
[System.IO.Compression.ZipFileExtensions]::ExtractToDirectory($zipFile, $unzipFolder)#, $true)
$zipFile.Dispose()
Remove-Item $outFile -Force
# install fonts
$shellApp = New-Object -ComObject shell.application
$fonts = $shellApp.NameSpace(0x14)
foreach ($font in $(Get-ChildItem $unzipFolder -Filter *.ttf)) {
$fonts.CopyHere($font.FullName)
}
}
# install terminal-icons in windows powershell and powershell
Install-Module -Name terminal-icons -Scope CurrentUser -force
# add terminal-icon import to profile
$content = get-content $profile.CurrentUserAllHosts
if (! ($content -match 'Import-Module Terminal-Icons')){
'Import-Module Terminal-Icons'|Out-File -FilePath $profile.CurrentUserAllHosts -Append -Encoding ascii
}
# install oh-my-posh
#choco install oy-my-posh -y
# download omp template from gist
$ompTemplateUri = "https://gist.githubusercontent.com/lindnerbrewery/bed217b6b9dd59696a2b732a3c918d2d/raw/my.omp.json"
$ompTemplateName = $(Split-Path $ompTemplateUri -Leaf)
$ompTemplateFullpath = Join-Path ([System.Environment]::GetEnvironmentVariable("POSH_THEMES_PATH",'machine')) $ompTemplateName
Invoke-WebRequest -uri $ompTemplateUri -OutFile $ompTemplateFullpath
# add oh-my-posh import to profile
$content = get-content $profile.CurrentUserAllHosts
# look for omp init
$ompInit = ($content -match 'oh-my-posh init')
$newompInit = "oh-my-posh init pwsh --config '$ompTemplateFullpath' | Invoke-Expression"
if ($ompInit){
$content = $content.Replace($ompInit, $newompInit)
}else {
$content += $newompInit
}
$content | Out-File -FilePath $profile.CurrentUserAllHosts -Encoding ascii -force
. $profile.CurrentUserAllHosts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment