Skip to content

Instantly share code, notes, and snippets.

@krymtkts
Last active December 4, 2021 08:26
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 krymtkts/6f7e365fd1683d6edeb7e531f725d280 to your computer and use it in GitHub Desktop.
Save krymtkts/6f7e365fd1683d6edeb7e531f725d280 to your computer and use it in GitHub Desktop.
My own oh-my-posh v2 theme.
#requires -Version 2 -Modules posh-git
function Write-Theme {
param(
[bool]
$lastCommandFailed,
[string]
$with
)
# Write the time bar.
$now = Get-Date -UFormat '%Y-%m-%d %H:%M:%S'
$backwardSymbol = $sl.PromptSymbols.SegmentBackwardSymbol
If ($lastCommandFailed) {
$rightText = " $($sl.PromptSymbols.FailedCommandSymbol) $now "
$backgroundColor = $sl.Colors.CommandFailedIconBackgroundColor
}
else {
$rightText = " $now "
$backgroundColor = $sl.Colors.TimestampBackgroundColor
}
$rightLength = $rightText.Length + $backwardSymbol.Length
$prompt += Set-CursorForRightBlockWrite -textLength $rightLength
$prompt += Write-Prompt $backwardSymbol -ForegroundColor $backgroundColor -BackgroundColor $sl.Colors.SessionInfoBackgroundColor
$prompt += Write-Prompt $rightText -ForegroundColor $sl.Colors.PromptForegroundColor -BackgroundColor $backgroundColor
$prompt += Write-Prompt -Object "`r"
# Write the workspace bar.
if (Test-VirtualEnv) {
$prompt += Write-Prompt -Object "$($sl.PromptSymbols.SegmentForwardSymbol) " -ForegroundColor $sl.Colors.SessionInfoBackgroundColor -BackgroundColor $sl.Colors.VirtualEnvBackgroundColor
$prompt += Write-Prompt -Object "$($sl.PromptSymbols.VirtualEnvSymbol) $(Get-VirtualEnvName) " -ForegroundColor $sl.Colors.VirtualEnvForegroundColor -BackgroundColor $sl.Colors.VirtualEnvBackgroundColor
$prompt += Write-Prompt -Object "$($sl.PromptSymbols.SegmentForwardSymbol) " -ForegroundColor $sl.Colors.VirtualEnvBackgroundColor -BackgroundColor $sl.Colors.PromptBackgroundColor
}
$prompt += Write-Prompt -Object "$(Get-ShortPath -dir $pwd) " -ForegroundColor $sl.Colors.PromptForegroundColor -BackgroundColor $sl.Colors.PromptBackgroundColor
$lastColor = $sl.Colors.PromptBackgroundColor
$status = Get-VCSStatus
if ($status) {
$themeInfo = Get-VcsInfo -status ($status)
$lastColor = $themeInfo.BackgroundColor
$prompt += Write-Prompt -Object $sl.PromptSymbols.SegmentForwardSymbol -ForegroundColor $sl.Colors.PromptBackgroundColor -BackgroundColor $lastColor
$prompt += Write-Prompt -Object " $($themeInfo.VcInfo) " -BackgroundColor $lastColor -ForegroundColor $sl.Colors.GitForegroundColor
}
if ($with) {
$prompt += Write-Prompt -Object $sl.PromptSymbols.SegmentForwardSymbol -ForegroundColor $lastColor -BackgroundColor $sl.Colors.WithBackgroundColor
$prompt += Write-Prompt -Object " $($with.ToUpper()) " -BackgroundColor $sl.Colors.WithBackgroundColor -ForegroundColor $sl.Colors.WithForegroundColor
$lastColor = $sl.Colors.WithBackgroundColor
}
$prompt += Write-Prompt -Object $sl.PromptSymbols.SegmentForwardSymbol -ForegroundColor $lastColor
# Writes the command bar.
$prompt += Set-Newline
If (Test-Administrator) {
$lastColor = $sl.Colors.AdminIconBackgroundColor
$prompt += Write-Prompt -Object $sl.PromptSymbols.ElevatedSymbol -ForegroundColor $sl.Colors.AdminIconForegroundColor -BackgroundColor $lastColor
}
else {
$lastColor = $sl.Colors.PromptBackgroundColor
$prompt += Write-Prompt -Object $sl.PromptSymbols.StartSymbol -ForegroundColor $sl.Colors.SessionInfoForegroundColor -BackgroundColor $lastColor
}
if (Test-NotDefaultUser($sl.CurrentUser)) {
$prompt += Write-Prompt -Object " $($sl.CurrentUser) " -ForegroundColor $sl.Colors.SessionInfoForegroundColor -BackgroundColor $lastColor
$prompt += Write-Prompt -Object "$($sl.PromptSymbols.SegmentForwardSymbol) " -ForegroundColor $lastColor -BackgroundColor $sl.Colors.SessionInfoBackgroundColor
}
$prompt
}
$sl = $global:ThemeSettings #local settings
$sl.PromptSymbols.ElevatedSymbol = [char]::ConvertFromUtf32(0x26A1) # ⚡
$sl.PromptSymbols.FailedCommandSymbol = [char]::ConvertFromUtf32(0x1F480) # 💀
$sl.PromptSymbols.HomeSymbol = [char]::ConvertFromUtf32(0x1F3E0) # 🏠
$sl.PromptSymbols.SegmentForwardSymbol = [char]::ConvertFromUtf32(0xE0BC) # 
$sl.PromptSymbols.SegmentBackwardSymbol = [char]::ConvertFromUtf32(0xE0BE) # 
$sl.PromptSymbols.StartSymbol = [char]::ConvertFromUtf32(0x1f916) # 🤖
$sl.PromptSymbols.PathSeparator = '/'
$sl.PromptSymbols.TruncatedFolderSymbol = '.'
$sl.Colors.AdminIconBackgroundColor = [ConsoleColor]::DarkMagenta
$sl.Colors.CommandFailedIconBackgroundColor = [ConsoleColor]::DarkRed
$sl.Colors.GitForegroundColor = [ConsoleColor]::Black
$sl.Colors.PromptForegroundColor = [ConsoleColor]::White
$sl.Colors.PromptSymbolColor = [ConsoleColor]::White
$sl.Colors.PromptHighlightColor = [ConsoleColor]::DarkBlue
$sl.Colors.TimestampBackgroundColor = [ConsoleColor]::DarkGray
$sl.Colors.VirtualEnvBackgroundColor = [ConsoleColor]::Red
$sl.Colors.VirtualEnvForegroundColor = [ConsoleColor]::White
$sl.Colors.WithForegroundColor = [ConsoleColor]::White
$sl.Colors.WithBackgroundColor = [ConsoleColor]::DarkRed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment