Skip to content

Instantly share code, notes, and snippets.

@byBretema
Created June 8, 2020 09:52
Show Gist options
  • Save byBretema/031516219e5046d40b0f5a771755129b to your computer and use it in GitHub Desktop.
Save byBretema/031516219e5046d40b0f5a771755129b to your computer and use it in GitHub Desktop.
Custom theme for ohmyposh module based on Zash
#requires -Version 2 -Modules posh-git
function Write-Theme {
param(
[bool]
$lastCommandFailed,
[string]
$with
)
$user=$sl.CurrentUser
#check the last command state and indicate if failed and change the colors of the arrows
If ($lastCommandFailed) {
$prompt += Write-Prompt -Object ([char]::ConvertFromUtf32(0x1F525)+' : ') -ForegroundColor $sl.Colors.PromptNeutral
}
$prompt += Write-Prompt -Object ([char]::ConvertFromUtf32(0x1F552) + $(Get-Date -UFormat %R) ) -ForegroundColor $sl.Colors.PromptSymbolColor
$prompt += Write-Prompt -Object (" " + [char]::ConvertFromUtf32(0x1F4BB) + $user) -ForegroundColor $sl.Colors.WithForegroundColor
# Writes the drive portion
$prompt += Write-Prompt -Object (" " + [char]::ConvertFromUtf32(0x1F4C2))
$drive = $sl.PromptSymbols.HomeSymbol
if ($pwd.Path -ne $HOME) {
$drive = "$(Split-Path -path $pwd -Leaf)"
}
$prompt += Write-Prompt -Object $drive -ForegroundColor $sl.Colors.DriveForegroundColor
$status = Get-VCSStatus
if ($status) {
if ($status.Working.Length -gt 0) {
$prompt += Write-Prompt -Object (" " + [char]::ConvertFromUtf32(0x1F52E))
} else {
$prompt += Write-Prompt -Object (" " + [char]::ConvertFromUtf32(0x1F52E))
}
$prompt += Write-Prompt -Object "git(" -ForegroundColor $sl.Colors.PromptHighlightColor
$prompt += Write-Prompt -Object "$($status.Branch)" -ForegroundColor $sl.Colors.GitDefaultColor
$prompt += Write-Prompt -Object ")" -ForegroundColor $sl.Colors.PromptHighlightColor
}
if ($with) {
$prompt += Write-Prompt -Object "$($with.ToUpper()) " -BackgroundColor $sl.Colors.WithBackgroundColor -ForegroundColor $sl.Colors.WithForegroundColor
}
$prompt += " " + [char]::ConvertFromUtf32(0x276F) + " "
$prompt
}
$sl = $global:ThemeSettings #local settings
$sl.PromptSymbols.HomeSymbol = '~'
$sl.Colors.PromptSymbolColor = [ConsoleColor]::Green
$sl.Colors.PromptHighlightColor = [ConsoleColor]::Blue
$sl.Colors.DriveForegroundColor = [ConsoleColor]::Cyan
$sl.Colors.WithForegroundColor = [ConsoleColor]::Red
$sl.Colors.GitDefaultColor = [ConsoleColor]::Yellow
$sl.Colors.NeutralColor = [ConsoleColor]::White
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment