Skip to content

Instantly share code, notes, and snippets.

@SirJson
Created September 19, 2020 04:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SirJson/02dd21eda191607682f9fb00847baaf1 to your computer and use it in GitHub Desktop.
Save SirJson/02dd21eda191607682f9fb00847baaf1 to your computer and use it in GitHub Desktop.
Powerlevel10k-Theme color mod for PowerShell

Powerlevel10k-Improved.psm1

This is a quick and dirty mod to my p10k theme port for oh-my-posh that keeps color accuracy with the original.

Requirements

Usage

Copy 'Powerlevel10k-Improved.psm1' into your user oh-my-posh theme folder. Usually, that is ~\Documents\WindowsPowerShell\PoshThemes or ~\Documents\PowerShell\PoshThemes.

With the file in place open a new PowerShell session and a new theme should be available: Powerlevel10k-Improved. You can test this by entering this command:

Set-Theme Powerlevel10k-Improved
#requires -Version 2 -Modules posh-git
Import-Module PowerColorTerm
function Write-Theme {
param(
[bool]
$lastCommandFailed,
[string]
$with
)
$adminsymbol = $sl.PromptSymbols.ElevatedSymbol
$venvsymbol = $sl.PromptSymbols.VirtualEnvSymbol
$clocksymbol = $sl.PromptSymbols.ClockSymbol
$bg = "#303030"
$subfwd = Get-RGB "{fg:#727272;bg:$bg}$($sl.PromptSymbols.SegmentSubForwardSymbol) {clc}"
## Left Part
$prompt = Write-Prompt -Object $(Get-RGB "{fg:#EEEEEE;bg:$bg} $($sl.PromptSymbols.StartSymbol) {clc}")
$prompt += $subfwd
$pathSymbol = if ($pwd.Path -eq $HOME) { $sl.PromptSymbols.PathHomeSymbol } else { $sl.PromptSymbols.PathSymbol }
# Writes the drive portion
$path = Get-RGB "{fg:#0087AF;bg:$bg}$pathSymbol $(Get-FullPath -dir $pwd) {clc}"
$prompt += Write-Prompt -Object $path
$status = Get-VCSStatus
if ($status) {
$themeInfo = Get-VcsInfo -status ($status)
$prompt += $subfwd
$prompt += Write-Prompt -Object $(Get-RGB "{fg:#5AC405;bg:$bg}$($themeInfo.VcInfo) {clc}")
}
If ($with) {
$sWith = " $($with.ToUpper())"
$prompt += $subfwd
$prompt += Write-Prompt -Object $sWith -ForegroundColor $sl.Colors.WithForegroundColor -BackgroundColor $sl.Colors.SessionInfoBackgroundColor
}
$prompt += Write-Prompt -Object $(Get-RGB "{fg:$bg}$($sl.PromptSymbols.SegmentForwardSymbol) {clc}")
###
## Right Part
$rightElements = New-Object 'System.Collections.Generic.List[Tuple[string,ConsoleColor]]'
$login = $sl.CurrentUser
$computer = [System.Environment]::MachineName;
$rightElements.Add([System.Tuple]::Create($sl.PromptSymbols.SegmentBackwardSymbol, $sl.Colors.SessionInfoBackgroundColor))
# List of all right elements
if (Test-VirtualEnv) {
$rightElements.Add([System.Tuple]::Create(" $(Get-VirtualEnvName) $venvsymbol ", $sl.Colors.VirtualEnvForegroundColor))
$rightElements.Add([System.Tuple]::Create($sl.PromptSymbols.SegmentSubBackwardSymbol, $sl.Colors.PromptForegroundColor))
}
if (Test-Administrator) {
$rightElements.Add([System.Tuple]::Create(" $adminsymbol", $sl.Colors.AdminIconForegroundColor))
}
$rightElements.Add([System.Tuple]::Create(" $login@$computer ", $sl.Colors.UserForegroundColor))
$rightElements.Add([System.Tuple]::Create($sl.PromptSymbols.SegmentSubBackwardSymbol, $sl.Colors.PromptForegroundColor))
$rightElements.Add([System.Tuple]::Create(" $(Get-Date -Format HH:mm:ss) $clocksymbol ", $sl.Colors.TimestampForegroundColor))
$lengthList = [Linq.Enumerable]::Select($rightElements, [Func[Tuple[string, ConsoleColor], int]] { $args[0].Item1.Length })
$total = [Linq.Enumerable]::Sum($lengthList)
# Transform into total length
$prompt += Set-CursorForRightBlockWrite -textLength $total
# The line head needs special care and is always drawn
$rsym = $rightElements[0].Item1
$prompt += Write-Prompt -Object $(Get-RGB "{fg:$bg}$rsym{clc}")
for ($i = 1; $i -lt $rightElements.Count; $i++) {
$item = $rightElements[$i].Item1
$prompt += Write-Prompt -Object $(Get-RGB "{fg:#5F8787;bg:$bg}$item{clc}")
}
###
$prompt += Write-Prompt -Object "`r"
$prompt += Set-Newline
# Writes the postfixes to the prompt
$indicatorColor = If ($lastCommandFailed) { $sl.Colors.CommandFailedIconForegroundColor } Else { $sl.Colors.PromptSymbolColor }
$prompt += Write-Prompt -Object $sl.PromptSymbols.PromptIndicator -ForegroundColor $indicatorColor
$prompt += ' '
$prompt
}
$sl = $global:ThemeSettings #local settings
$sl.PromptSymbols.StartSymbol = [char]::ConvertFromUtf32(0xe62a)
$sl.PromptSymbols.PromptIndicator = [char]::ConvertFromUtf32(0x276F)
$sl.PromptSymbols.SegmentForwardSymbol = [char]::ConvertFromUtf32(0xE0B0)
$sl.PromptSymbols.SegmentSubForwardSymbol = [char]::ConvertFromUtf32(0xE0B1)
$sl.PromptSymbols.SegmentBackwardSymbol = [char]::ConvertFromUtf32(0xE0B2)
$sl.PromptSymbols.SegmentSubBackwardSymbol = [char]::ConvertFromUtf32(0xE0B3)
$sl.PromptSymbols.ClockSymbol = [char]::ConvertFromUtf32(0xf64f)
$sl.PromptSymbols.PathHomeSymbol = [char]::ConvertFromUtf32(0xf015)
$sl.PromptSymbols.PathSymbol = [char]::ConvertFromUtf32(0xf07c)
$sl.Colors.PromptBackgroundColor = [ConsoleColor]::DarkGray
$sl.Colors.SessionInfoBackgroundColor = [ConsoleColor]::DarkGray
$sl.Colors.VirtualEnvBackgroundColor = [ConsoleColor]::DarkGray
$sl.Colors.PromptSymbolColor = [ConsoleColor]::Green
$sl.Colors.CommandFailedIconForegroundColor = [ConsoleColor]::DarkRed
$sl.Colors.DriveForegroundColor = [ConsoleColor]::Cyan
$sl.Colors.PromptForegroundColor = [ConsoleColor]::Gray
$sl.Colors.SessionInfoForegroundColor = [ConsoleColor]::White
$sl.Colors.WithForegroundColor = [ConsoleColor]::Red
$sl.Colors.VirtualEnvForegroundColor = [System.ConsoleColor]::Magenta
$sl.Colors.TimestampForegroundColor = [ConsoleColor]::Green
$sl.Colors.UserForegroundColor = [ConsoleColor]::Yellow
$sl.Colors.GitForegroundColor = [ConsoleColor]::White # Just in case...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment