fix: wrong stack count when init from Set-PoshPrompt

This commit is contained in:
lnu 2021-04-14 00:15:32 +02:00 committed by Jan De Dobbeleer
parent b9601b632a
commit 4f96cc0f7c
2 changed files with 11 additions and 1 deletions

View file

@ -56,6 +56,11 @@ function Set-PoshPrompt {
$config = "$PSScriptRoot/themes/jandedobbeleer.omp.json"
}
# Workaround for get-location/push-location/pop-location from within a module
# https://github.com/PowerShell/PowerShell/issues/12868
# https://github.com/JanDeDobbeleer/oh-my-posh2/issues/113
$global:omp_global_sessionstate = $PSCmdlet.SessionState
$poshCommand = Get-PoshCommand
Invoke-Expression (& $poshCommand --init --shell=pwsh --config="$config")
}

View file

@ -65,7 +65,12 @@ function global:Initialize-ModuleSupport {
}
}
$stackCount = (Get-Location -Stack).Count
$stackCount = 0
try {
$stackCount = ($global:omp_global_sessionstate).path.locationstack('').count
}
catch {}
$executionTime = -1
$history = Get-History -ErrorAction Ignore -Count 1
if ($null -ne $history -and $null -ne $history.EndExecutionTime -and $null -ne $history.StartExecutionTime -and $global:omp_lastHistoryId -ne $history.Id) {