Skip to content

Instantly share code, notes, and snippets.

@mkarvalho
Last active March 27, 2020 01:27
Show Gist options
  • Select an option

  • Save mkarvalho/cb8708dea31690c03f125f862e542581 to your computer and use it in GitHub Desktop.

Select an option

Save mkarvalho/cb8708dea31690c03f125f862e542581 to your computer and use it in GitHub Desktop.
oh-my-posh
Import-Module 'C:\tools\poshgit\dahlbyk-posh-git-9bda399\src\posh-git.psd1'
Import-Module posh-git
Import-Module oh-my-posh
Set-Theme mytheme
#requires -Version 2 -Modules posh-git
function Write-Theme
{
param(
[bool]
$lastCommandFailed,
[string]
$with
)
#write symbol and space
$prompt += Write-Prompt -Object ($sl.PromptSymbols.HomeSymbol) -BackgroundColor $promtSymbolColor
# write user
$user = $sl.CurrentUser
if (Test-NotDefaultUser($user)) {
$prompt += Write-Prompt -Object " $user" -ForegroundColor $sl.Colors.WithBackgroundColor
# write in for folder
}
# write folder
#$dir = Get-FullPath -dir $pwd
#$prompt += Write-Prompt -Object " $dir " -ForegroundColor $sl.Colors.DriveForegroundColor
$drive = $sl.PromptSymbols.HomeSymbol
if ($pwd.Path -ne $HOME) {
$prompt += Write-Prompt -Object " in " -ForegroundColor $sl.Colors.PromptForegroundColor
$drive = "$(Split-Path -path $pwd -noQualifier)"
}
$prompt += Write-Prompt -Object ($drive) -ForegroundColor $sl.Colors.DriveForegroundColor
# write on (git:branchname status)
$status = Get-VCSStatus
if ($status) {
$prompt += Write-Prompt -Object " on" -ForegroundColor $sl.Colors.PromptForegroundColor
$prompt += Write-Prompt -Object " git:(" -ForegroundColor $sl.Colors.PromptHighlightColor
$prompt += Write-Prompt -Object "$($status.Branch)" -ForegroundColor $sl.Colors.WithForegroundColor
$prompt += Write-Prompt -Object ")" -ForegroundColor $sl.Colors.PromptHighlightColor
if ($status.Working.Length -gt 0) {
$prompt += Write-Prompt -Object (" " + $sl.PromptSymbols.GitDirtyIndicator) -ForegroundColor $sl.Colors.GitDefaultColor
}
}
# check the last command state and indicate if failed
$promtSymbolColor = $sl.Colors.PromptSymbolColor
If ($lastCommandFailed) {
$promtSymbolColor = $sl.Colors.WithForegroundColor
}
$prompt += Set-Newline
$prompt += Write-Prompt -Object ($sl.PromptSymbols.PromptIndicator + " ") -ForegroundColor $promtSymbolColor
}
$sl = $global:ThemeSettings #local settings
$ThemeSettings.PromptSymbols.PromptIndicator = [char]::ConvertFromUtf32(0x0000276F)
$sl.Colors.AdminIconForegroundColor = [ConsoleColor]::DarkYellow
$sl.Colors.CommandFailedIconForegroundColor = [ConsoleColor]::DarkRed
$sl.Colors.DriveForegroundColor = [ConsoleColor]::Cyan
$sl.Colors.GitDefaultColor = [ConsoleColor]::Yellow
$sl.Colors.GitForegroundColor = [ConsoleColor]::Black
$sl.Colors.GitLocalChangesColor = [ConsoleColor]::DarkYellow
$sl.Colors.GitNoLocalChangesAndAheadAndBehindColor = [ConsoleColor]::DarkRed
$sl.Colors.GitNoLocalChangesAndAheadColor = [ConsoleColor]::DarkMagenta
$sl.Colors.GitNoLocalChangesAndBehindColor = [ConsoleColor]::DarkRed
$sl.Colors.PromptBackgroundColor = [ConsoleColor]::DarkBlue
$sl.Colors.PromptForegroundColor = [ConsoleColor]::White
$sl.Colors.PromptHighlightColor = [ConsoleColor]::Blue
$sl.Colors.PromptSymbolColor = [ConsoleColor]::Green
$sl.Colors.SessionInfoBackgroundColor = [ConsoleColor]::Black
$sl.Colors.SessionInfoForegroundColor = [ConsoleColor]::White
$sl.Colors.VirtualEnvBackgroundColor = [ConsoleColor]::Red
$sl.Colors.VirtualEnvForegroundColor = [ConsoleColor]::White
$sl.Colors.WithBackgroundColor = [ConsoleColor]::Magenta
$sl.Colors.WithForegroundColor = [ConsoleColor]::Red
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment