Skip to content

Commit

Permalink
fix: wrong stack count when init from Set-PoshPrompt
Browse files Browse the repository at this point in the history
  • Loading branch information
lnu authored and JanDeDobbeleer committed Apr 14, 2021
1 parent b9601b6 commit 4f96cc0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/powershell/oh-my-posh/oh-my-posh.psm1
Expand Up @@ -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")
}
Expand Down
7 changes: 6 additions & 1 deletion src/init/omp.ps1
Expand Up @@ -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) {
Expand Down

0 comments on commit 4f96cc0

Please sign in to comment.