2020-12-22 10:31:20 -08:00
|
|
|
$global:PoshSettings = New-Object -TypeName PSObject -Property @{
|
|
|
|
Theme = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Test-Path "::CONFIG::") {
|
|
|
|
$global:PoshSettings.Theme = Resolve-Path -Path "::CONFIG::"
|
|
|
|
}
|
|
|
|
|
2021-01-17 04:13:00 -08:00
|
|
|
function global:Set-PoshContext {}
|
|
|
|
|
|
|
|
function global:Set-PoshGitStatus {
|
2021-01-07 04:17:06 -08:00
|
|
|
if (Get-Module -Name "posh-git") {
|
2020-12-27 08:53:58 -08:00
|
|
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSProvideCommentHelp', '', Justification='Variable used later(not in this scope)')]
|
2020-12-22 10:31:20 -08:00
|
|
|
$Global:GitStatus = Get-GitStatus
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[ScriptBlock]$Prompt = {
|
|
|
|
#store if the last command was successfull
|
|
|
|
$lastCommandSuccess = $?
|
|
|
|
#store the last exit code for restore
|
|
|
|
$realLASTEXITCODE = $global:LASTEXITCODE
|
|
|
|
$errorCode = 0
|
|
|
|
Set-PoshContext
|
|
|
|
if ($lastCommandSuccess -eq $false) {
|
|
|
|
#native app exit code
|
|
|
|
if ($realLASTEXITCODE -is [int] -and $realLASTEXITCODE -gt 0) {
|
|
|
|
$errorCode = $realLASTEXITCODE
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$errorCode = 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$executionTime = -1
|
|
|
|
$history = Get-History -ErrorAction Ignore -Count 1
|
|
|
|
if ($null -ne $history -and $null -ne $history.EndExecutionTime -and $null -ne $history.StartExecutionTime) {
|
|
|
|
$executionTime = ($history.EndExecutionTime - $history.StartExecutionTime).TotalMilliseconds
|
|
|
|
}
|
2021-01-17 04:08:08 -08:00
|
|
|
# Save current encoding and swap for UTF8
|
|
|
|
$originalOutputEncoding = [Console]::OutputEncoding
|
|
|
|
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
|
|
|
$omp = "::OMP::"
|
2020-12-22 10:31:20 -08:00
|
|
|
$config = $global:PoshSettings.Theme
|
|
|
|
$cleanPWD = $PWD.ProviderPath.TrimEnd("\")
|
2021-01-09 04:48:54 -08:00
|
|
|
$cleanPSWD = $PWD.ToString().TrimEnd("\")
|
2021-01-17 04:08:08 -08:00
|
|
|
$standardOut = @(&$omp "--config=$config" "--error=$errorCode" "--pwd=$cleanPWD" "--pswd=$cleanPSWD" "--execution-time=$executionTime")
|
|
|
|
# Restore initial encoding
|
|
|
|
[Console]::OutputEncoding = $originalOutputEncoding
|
2021-01-18 02:16:31 -08:00
|
|
|
# the ouput can be multiline, joining these ensures proper rendering by adding line breaks with `n
|
|
|
|
$standardOut -join "`n"
|
2021-01-17 04:13:00 -08:00
|
|
|
Set-PoshGitStatus
|
2020-12-22 10:31:20 -08:00
|
|
|
$global:LASTEXITCODE = $realLASTEXITCODE
|
|
|
|
#remove temp variables
|
|
|
|
Remove-Variable realLASTEXITCODE -Confirm:$false
|
|
|
|
Remove-Variable lastCommandSuccess -Confirm:$false
|
|
|
|
}
|
|
|
|
Set-Item -Path Function:prompt -Value $Prompt -Force
|