Last active
February 11, 2021 23:54
-
-
Save UlanaXY/de5bf2a300674f7f89a7bb66eb538fab to your computer and use it in GitHub Desktop.
ulnTheme - oh-my-posh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#requires -Version 2 -Modules posh-git | |
function Write-Theme { | |
param( | |
[bool] | |
$lastCommandFailed, | |
[string] | |
$with | |
) | |
# timestamp | |
$prompt = Write-Prompt -Object "[ $(Get-Date -Format HH:mm:ss) ] " -ForegroundColor $sl.Colors.PromptForegroundColor | |
$lastColor = $sl.Colors.PromptBackgroundColor | |
$prompt = Write-Prompt -Object $sl.PromptSymbols.StartSymbol -ForegroundColor $sl.Colors.PromptForegroundColor -BackgroundColor $sl.Colors.SessionInfoBackgroundColor | |
#check the last command state and indicate if failed | |
If ($lastCommandFailed) { | |
$prompt += Write-Prompt -Object "$($sl.PromptSymbols.FailedCommandSymbol) " -ForegroundColor $sl.Colors.CommandFailedIconForegroundColor -BackgroundColor $sl.Colors.SessionInfoBackgroundColor | |
} | |
#check for elevated prompt | |
If (Test-Administrator) { | |
$prompt += Write-Prompt -Object "$($sl.PromptSymbols.ElevatedSymbol) " -ForegroundColor $sl.Colors.AdminIconForegroundColor -BackgroundColor $sl.Colors.SessionInfoBackgroundColor | |
} | |
$user = $sl.CurrentUser | |
$computer = $sl.CurrentHostname | |
$driveName = $pwd.drive.name | |
$path = (Get-FullPath -dir $pwd).Split(":")[1] | |
if (Test-VirtualEnv) { | |
$prompt += Write-Prompt -Object " " -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.DriveForegroundColor | |
} | |
else { | |
$prompt += Write-Prompt -Object " " -ForegroundColor $sl.Colors.SessionInfoBackgroundColor -BackgroundColor $sl.Colors.DriveForegroundColor | |
} | |
# Writes the drive portion | |
$prompt += Write-Prompt -Object "$driveName " -ForegroundColor $sl.Colors.PromptForegroundColor -BackgroundColor $sl.Colors.DriveForegroundColor | |
$prompt += Write-Prompt -Object "$($sl.PromptSymbols.SegmentForwardSymbol) " -ForegroundColor $sl.Colors.DriveForegroundColor -BackgroundColor $sl.Colors.PromptBackgroundColor | |
$prompt += Write-Prompt -Object "$path " -ForegroundColor $sl.Colors.PromptForegroundColor -BackgroundColor $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 | |
} | |
# Writes the postfix to the prompt | |
$prompt += Write-Prompt -Object $sl.PromptSymbols.SegmentForwardSymbol -ForegroundColor $lastColor | |
$prompt += Set-Newline | |
if (Test-NotDefaultUser($user)) { | |
$prompt += Write-Prompt -Object "$user@$computer " -ForegroundColor $sl.Colors.SessionInfoForegroundColor | |
} | |
if ($with) { | |
$prompt += Write-Prompt -Object "$($with.ToUpper()) " -BackgroundColor $sl.Colors.WithBackgroundColor -ForegroundColor $sl.Colors.WithForegroundColor | |
} | |
$prompt += Write-Prompt -Object ($sl.PromptSymbols.PromptIndicator) -ForegroundColor $sl.Colors.PromptSymbolColor | |
$prompt += ' ' | |
$prompt | |
} | |
$sl = $global:ThemeSettings #local settings | |
$sl.PromptSymbols.StartSymbol = '' | |
$sl.PromptSymbols.PromptIndicator = [char]::ConvertFromUtf32(0x276F) | |
$sl.PromptSymbols.SegmentForwardSymbol = [char]::ConvertFromUtf32(0xE0B0) | |
$sl.Colors.DriveForegroundColor = [ConsoleColor]::Blue | |
$sl.Colors.PromptForegroundColor = [ConsoleColor]::White | |
$sl.Colors.PromptSymbolColor = [ConsoleColor]::White | |
$sl.Colors.PromptHighlightColor = [ConsoleColor]::DarkBlue | |
$sl.Colors.GitForegroundColor = [ConsoleColor]::Black | |
$sl.Colors.WithForegroundColor = [ConsoleColor]::DarkRed | |
$sl.Colors.WithBackgroundColor = [ConsoleColor]::Magenta | |
$sl.Colors.VirtualEnvBackgroundColor = [System.ConsoleColor]::DarkGreen | |
$sl.Colors.VirtualEnvForegroundColor = [System.ConsoleColor]::White |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment