Skip to content

Instantly share code, notes, and snippets.

@abdellatifLabr
Created August 29, 2020 14:37
Show Gist options
  • Save abdellatifLabr/76b5d39020dc25b148c548a94479de06 to your computer and use it in GitHub Desktop.
Save abdellatifLabr/76b5d39020dc25b148c548a94479de06 to your computer and use it in GitHub Desktop.
Powershell 7 oh-my-posh Lite theme
#requires -Version 2 -Modules posh-git
function Write-Theme {
param(
[bool]
$lastCommandFailed,
[string]
$with
)
$lastColor = $sl.Colors.PromptBackgroundColor
#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
}
if (Test-VirtualEnv) {
$prompt += Write-Prompt -Object "($(Get-VirtualEnvName)) " -ForegroundColor $sl.Colors.VirtualEnvForegroundColor -BackgroundColor $sl.Colors.SessionInfoBackgroundColor
}
<# $user = $sl.CurrentUser
$computer = $sl.CurrentHostname
if (Test-NotDefaultUser($user)) {
$prompt += Write-Prompt -Object "$($user)@$($computer) " -ForegroundColor $sl.Colors.UserMachineForegroundColor -BackgroundColor $sl.Colors.SessionInfoBackgroundColor
} #>
$status = Get-VCSStatus
if ($status) {
$themeInfo = Get-VcsInfo -status ($status)
$lastColor = $themeInfo.BackgroundColor
$prompt += Write-Prompt -Object "($($themeInfo.VcInfo)) " -BackgroundColor $sl.Colors.SessionInfoBackgroundColor -ForegroundColor $lastColor
}
if ($with) {
$prompt += Write-Prompt -Object $sl.PromptSymbols.SegmentForwardSymbol -ForegroundColor $lastColor -BackgroundColor $sl.Colors.SessionInfoBackgroundColor
$prompt += Write-Prompt -Object " $($with.ToUpper()) " -BackgroundColor $sl.Colors.SessionInfoBackgroundColor -ForegroundColor $sl.Colors.WithForegroundColor
$lastColor = $sl.Colors.WithBackgroundColor
}
# Writes the drive portion
$prompt += Write-Prompt -Object "$($pwd)> " -ForegroundColor $sl.Colors.PromptForegroundColor -BackgroundColor $sl.Colors.SessionInfoBackgroundColor
# Writes the postfix to the prompt
$prompt
}
$sl = $global:ThemeSettings #local settings
$sl.Colors.VirtualEnvForegroundColor = [System.ConsoleColor]::DarkGray
$sl.Colors.UserMachineForegroundColor = [ConsoleColor]::White
$sl.Colors.PromptForegroundColor = [ConsoleColor]::Blue
$sl.Colors.GitForegroundColor = [ConsoleColor]::Black
$sl.Colors.WithForegroundColor = [ConsoleColor]::DarkRe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment