Skip to content

Instantly share code, notes, and snippets.

@rprouse
Last active December 5, 2020 08:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rprouse/f62f9dc9483419d982e9f942f66fd10b to your computer and use it in GitHub Desktop.
Save rprouse/f62f9dc9483419d982e9f942f66fd10b to your computer and use it in GitHub Desktop.
Theme for PowerShell oh-my-posh extension https://github.com/JanJoris/oh-my-posh
#requires -Version 2 -Modules posh-git
function Write-Theme {
param(
[bool]
$lastCommandFailed,
[string]
$with
)
$lastColor = $sl.Colors.PromptBackgroundColor
# Write-Prompt -Object $sl.PromptSymbols.StartSymbol -ForegroundColor $sl.Colors.SessionInfoForegroundColor -BackgroundColor $sl.Colors.SessionInfoBackgroundColor
#check the last command state and indicate if failed
# If ($lastCommandFailed) {
# Write-Prompt -Object "$($sl.PromptSymbols.FailedCommandSymbol) " -ForegroundColor $sl.Colors.CommandFailedIconForegroundColor -BackgroundColor $sl.Colors.SessionInfoBackgroundColor
# }
#Write-Prompt -Object "$($sl.PromptSymbols.SegmentBackwardSymbol) " -ForegroundColor Yellow -BackgroundColor $sl.Colors.SessionInfoBackgroundColor
$user = [Environment]::UserName
$computer = $env:computername
if (Test-NotDefaultUser($user)) {
Write-Prompt -Object "$user@$computer " -ForegroundColor $sl.Colors.SessionInfoForegroundColor -BackgroundColor $sl.Colors.SessionInfoBackgroundColor
}
if (Test-VirtualEnv) {
Write-Prompt -Object "$($sl.PromptSymbols.SegmentForwardSymbol) " -ForegroundColor Black -BackgroundColor $sl.Colors.VirtualEnvBackgroundColor
Write-Prompt -Object "$($sl.PromptSymbols.VirtualEnvSymbol) $(Get-VirtualEnvName) " -ForegroundColor $sl.Colors.VirtualEnvForegroundColor -BackgroundColor $sl.Colors.VirtualEnvBackgroundColor
Write-Prompt -Object "$($sl.PromptSymbols.SegmentForwardSymbol) " -ForegroundColor $sl.Colors.VirtualEnvBackgroundColor -BackgroundColor $sl.Colors.PromptBackgroundColor
}
else {
Write-Prompt -Object "$($sl.PromptSymbols.SegmentForwardSymbol) " -ForegroundColor Black -BackgroundColor $sl.Colors.PromptBackgroundColor
}
# Writes the drive portion
Write-Prompt -Object ($pwd) -ForegroundColor $sl.Colors.PromptForegroundColor -BackgroundColor $sl.Colors.PromptBackgroundColor
# Write-Prompt -Object (Get-ShortPath -dir $pwd) -ForegroundColor $sl.Colors.PromptForegroundColor -BackgroundColor $sl.Colors.PromptBackgroundColor
Write-Prompt -Object ' ' -ForegroundColor $sl.Colors.PromptForegroundColor -BackgroundColor $sl.Colors.PromptBackgroundColor
$status = Get-VCSStatus
if ($status) {
$themeInfo = Get-VcsInfo -status ($status)
$lastColor = $themeInfo.BackgroundColor
Write-Prompt -Object $sl.PromptSymbols.SegmentForwardSymbol -ForegroundColor $sl.Colors.PromptBackgroundColor -BackgroundColor $lastColor
Write-Prompt -Object " $($themeInfo.VcInfo) " -BackgroundColor $lastColor -ForegroundColor Black #$sl.Colors.GitForegroundColor
}
if ($with) {
Write-Prompt -Object $sl.PromptSymbols.SegmentForwardSymbol -ForegroundColor $lastColor -BackgroundColor $sl.Colors.WithBackgroundColor
Write-Prompt -Object " $($with.ToUpper()) " -BackgroundColor $sl.Colors.WithBackgroundColor -ForegroundColor $sl.Colors.WithForegroundColor
$lastColor = $sl.Colors.WithBackgroundColor
}
# Writes the postfix to the prompt
Write-Prompt -Object $sl.PromptSymbols.SegmentForwardSymbol -ForegroundColor $lastColor
# Newline
Write-Host
#check for elevated prompt
If (([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
Write-Prompt -Object "$($sl.PromptSymbols.ElevatedSymbol) " -ForegroundColor $sl.Colors.AdminIconForegroundColor -BackgroundColor $sl.Colors.SessionInfoBackgroundColor
}
else
{
Write-Prompt -Object "$($sl.PromptSymbols.PromptIndicator) " -ForegroundColor $sl.Colors.PromptSymbolColor -BackgroundColor $sl.Colors.SessionInfoBackgroundColor
}
}
$sl = $global:ThemeSettings #local settings
$sl.Colors.SessionInfoBackgroundColor = [System.ConsoleColor]::Black
$sl.Colors.GitDefaultColor = [System.ConsoleColor]::Green
$sl.Colors.PromptForegroundColor = [System.ConsoleColor]::White
$sl.Colors.GitLocalChangesColor = [System.ConsoleColor]::Yellow
$sl.Colors.VirtualEnvForegroundColor = [System.ConsoleColor]::White
$sl.Colors.DriveForegroundColor = [System.ConsoleColor]::Blue
$sl.Colors.SessionInfoForegroundColor = [System.ConsoleColor]::White
$sl.Colors.PromptHighlightColor = [System.ConsoleColor]::DarkBlue
$sl.Colors.AdminIconForegroundColor = [System.ConsoleColor]::DarkRed
$sl.Colors.CommandFailedIconForegroundColor = [System.ConsoleColor]::DarkRed
$sl.Colors.WithForegroundColor = [System.ConsoleColor]::White
$sl.Colors.GitForegroundColor = [System.ConsoleColor]::Black
$sl.Colors.PromptSymbolColor = [System.ConsoleColor]::Cyan
$sl.Colors.VirtualEnvBackgroundColor = [System.ConsoleColor]::Red
$sl.Colors.WithBackgroundColor = [System.ConsoleColor]::DarkRed
$sl.Colors.PromptBackgroundColor = [System.ConsoleColor]::Blue
$sl.Colors.GitNoLocalChangesAndAheadColor = [System.ConsoleColor]::Magenta
$sl.PromptSymbols.SegmentForwardSymbol = [char]::ConvertFromUtf32(0xE0B0)
$sl.PromptSymbols.PromptIndicator = [char]::ConvertFromUtf32(0x03BB)
$sl.PromptSymbols.ElevatedSymbol = [char]::ConvertFromUtf32(0x03A9)
#$sl.GitSymbols.BranchBehindStatusSymbol = [char]::ConvertFromUtf32(0x21E9)
#$sl.GitSymbols.BranchAheadStatusSymbol = [char]::ConvertFromUtf32(0x21E7)
$sl.GitSymbols.BranchUntrackedSymbol = [char]::ConvertFromUtf32(0xf192)
$sl.GitSymbols.BranchIdenticalStatusToSymbol = [char]::ConvertFromUtf32(0x2261)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment