Last active
July 23, 2020 06:33
-
-
Save LachlanArthur/4832a0fa716d1dd1166200a4c3c8582c to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
) | |
$E = [char]0x001b | |
$lastColor = $sl.Colors.SessionInfoBackgroundColor | |
Write-Prompt -Object $sl.PromptSymbols.StartSymbol -ForegroundColor $sl.Colors.SessionInfoBackgroundColor | |
Write-Prompt ' ' -BackgroundColor $sl.Colors.SessionInfoBackgroundColor | |
# #check the last command state and indicate if failed | |
# If ($lastCommandFailed) { | |
# $lastColor = $sl.Colors.SessionInfoBackgroundColor | |
# Write-Prompt -Object "$($sl.PromptSymbols.FailedCommandSymbol) " -ForegroundColor $sl.Colors.CommandFailedIconForegroundColor -BackgroundColor $sl.Colors.SessionInfoBackgroundColor | |
# } | |
#check for elevated prompt | |
If (Test-Administrator) { | |
Write-Prompt -Object "$($sl.PromptSymbols.ElevatedSymbol) " -ForegroundColor $sl.Colors.AdminIconForegroundColor -BackgroundColor $sl.Colors.SessionInfoBackgroundColor | |
} | |
$user = $sl.CurrentUser | |
$computer = $sl.CurrentHostname | |
$computer = [System.Net.Dns]::GetHostname(); # Correct case version of $env:ComputerName | |
$path = Get-FullPath -dir $pwd | |
$path = $ExecutionContext.SessionState.Path.CurrentLocation.Path | |
if (Test-NotDefaultUser($user)) { | |
Write-Prompt -Object "$user@$computer " -ForegroundColor $sl.Colors.SessionInfoForegroundColor -BackgroundColor $sl.Colors.SessionInfoBackgroundColor | |
} | |
if (Test-VirtualEnv) { | |
Write-Prompt -Object "$($sl.PromptSymbols.SegmentForwardSymbol) " -ForegroundColor $sl.Colors.SessionInfoBackgroundColor -BackgroundColor $sl.Colors.VirtualEnvBackgroundColor | |
Write-Prompt -Object "$($sl.PromptSymbols.VirtualEnvSymbol) $(Get-VirtualEnvName) " -ForegroundColor $sl.Colors.VirtualEnvForegroundColor -BackgroundColor $sl.Colors.VirtualEnvBackgroundColor | |
Write-Prompt -Object "$($sl.PromptSymbols.SegmentForwardSymbol) " -ForegroundColor $sl.Colors.VirtualEnvBackgroundColor -BackgroundColor $sl.Colors.PromptBackgroundColor | |
} | |
else { | |
Write-Prompt -Object "$($sl.PromptSymbols.SegmentForwardSymbol) " -ForegroundColor $sl.Colors.SessionInfoBackgroundColor -BackgroundColor $sl.Colors.PromptBackgroundColor | |
} | |
$pathAliases = @{ | |
"$Home" = "~" | |
"$Home\Source\" = " " | |
# Network drives | |
"Microsoft.PowerShell.Core\FileSystem::\\" = "\\" | |
} | |
# Replace path parts with aliases | |
foreach ( $aliasPath in $pathAliases.keys ) { | |
if ( $path.ToLower().StartsWith( $aliasPath.ToLower() ) ) { | |
$newPath = $pathAliases[$aliasPath] + $path.SubString( $aliasPath.Length ) | |
if ( $newPath.Length -lt $path.Length ) { | |
$path = $newPath | |
} | |
} | |
} | |
# Writes the drive portion | |
$lastColor = $sl.Colors.PromptBackgroundColor | |
Write-Prompt -Object "$path " -ForegroundColor $sl.Colors.PromptForegroundColor -BackgroundColor $sl.Colors.PromptBackgroundColor | |
$status = Get-VCSStatus | |
if ($status) { | |
$lastColor = $sl.Colors.PromptBackgroundColor | |
Write-Prompt -Object $($sl.PromptSymbols.SegmentForwardSymbol) -ForegroundColor $sl.Colors.PromptBackgroundColor | |
Write-VCSStatus | |
# Writes the postfix to the prompt | |
# Write-Prompt '' -ForegroundColor $lastColor | |
Write-Prompt '' -ForegroundColor $lastColor | |
} else { | |
# Writes the postfix to the prompt | |
Write-Prompt -Object $sl.PromptSymbols.SegmentForwardSymbol -ForegroundColor $lastColor | |
} | |
# $timeStamp = Get-Date -UFormat %R | |
# $timestamp = "[$timeStamp]" | |
# Set-CursorForRightBlockWrite -textLength ($timestamp.Length + 1) | |
# Write-Prompt $timeStamp -ForegroundColor $sl.Colors.PromptForegroundColor | |
Set-Newline | |
Write-Prompt '' -ForegroundColor $sl.Colors.PromptBackgroundColor | |
if ($with) { | |
Write-Prompt -Object "$($with.ToUpper()) " -BackgroundColor $sl.Colors.WithBackgroundColor -ForegroundColor $sl.Colors.WithForegroundColor | |
} | |
Write-Prompt -Object ($sl.PromptSymbols.PromptIndicator) -BackgroundColor $sl.Colors.PromptBackgroundColor -ForegroundColor $sl.Colors.PromptForegroundColor | |
Write-Prompt '' -ForegroundColor $sl.Colors.PromptBackgroundColor | |
Write-Prompt ' ' | |
} | |
$sl = $global:ThemeSettings #local settings | |
$sl.PromptSymbols.StartSymbol = '' | |
$sl.PromptSymbols.PromptIndicator = ' ' | |
$sl.PromptSymbols.SegmentForwardSymbol = '' | |
$sl.Colors.SessionInfoForegroundColor = [ConsoleColor]::Black | |
$sl.Colors.SessionInfoBackgroundColor = [ConsoleColor]::Green | |
$sl.Colors.PromptForegroundColor = [ConsoleColor]::Green | |
$sl.Colors.PromptBackgroundColor = [ConsoleColor]::DarkGray | |
$sl.Colors.PromptSymbolColor = [ConsoleColor]::White | |
$sl.Colors.PromptHighlightColor = [ConsoleColor]::DarkGray | |
$sl.Colors.GitForegroundColor = [ConsoleColor]::Black | |
$sl.Colors.WithForegroundColor = [ConsoleColor]::DarkRed | |
$sl.Colors.WithBackgroundColor = [ConsoleColor]::Magenta | |
$sl.Colors.VirtualEnvBackgroundColor = [System.ConsoleColor]::Red | |
$sl.Colors.VirtualEnvForegroundColor = [System.ConsoleColor]::White | |
$gps = $global:GitPromptSettings | |
$gps.BeforeForegroundColor = [ConsoleColor]::White | |
$gps.AfterForegroundColor = [ConsoleColor]::White | |
$gps.BeforeText = ' ' | |
$gps.AfterText = ' ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment