fix(pwsh): detect debug context correctly

This commit is contained in:
L. Yeung 2022-05-20 12:06:55 +08:00 committed by Jan De Dobbeleer
parent 1459cba70a
commit f84dac27e2

View file

@ -19,8 +19,8 @@ New-Module -Name "oh-my-posh-core" -ScriptBlock {
function Start-Utf8Process { function Start-Utf8Process {
param( param(
[string] $FileName, [string]$FileName,
[string[]] $Arguments = @() [string[]]$Arguments = @()
) )
$Process = New-Object System.Diagnostics.Process $Process = New-Object System.Diagnostics.Process
@ -124,19 +124,19 @@ New-Module -Name "oh-my-posh-core" -ScriptBlock {
.EXAMPLE .EXAMPLE
Export-PoshTheme Export-PoshTheme
Export the current theme in JSON to the clipboard. Exports the current theme in JSON to the clipboard.
.EXAMPLE .EXAMPLE
Export-PoshTheme -Format toml Export-PoshTheme -Format toml
Export the current theme in TOML to the clipboard. Exports the current theme in TOML to the clipboard.
.EXAMPLE .EXAMPLE
Export-PoshTheme C:\temp\theme.yaml yaml Export-PoshTheme C:\temp\theme.yaml yaml
Export the current theme in YAML to 'C:\temp\theme.yaml'. Exports the current theme in YAML to 'C:\temp\theme.yaml'.
.EXAMPLE .EXAMPLE
Export-PoshTheme ~\theme.toml toml Export-PoshTheme ~\theme.toml toml
Export the current theme in TOML to '$HOME\theme.toml' Exports the current theme in TOML to '$HOME\theme.toml'
#> #>
function Export-PoshTheme { function Export-PoshTheme {
param( param(
@ -147,7 +147,7 @@ New-Module -Name "oh-my-posh-core" -ScriptBlock {
[Parameter(Mandatory = $false)] [Parameter(Mandatory = $false)]
[ValidateSet('json', 'yaml', 'toml')] [ValidateSet('json', 'yaml', 'toml')]
[string] [string]
# The format of the theme # The format of the theme.
$Format = 'json' $Format = 'json'
) )
@ -244,7 +244,7 @@ Example:
$script:TransientPrompt = $false $script:TransientPrompt = $false
return return
} }
if (Test-Path variable:/PSDebugContext) { if (Test-PSDebugContext) {
@(Start-Utf8Process $script:OMPExecutable @("print", "debug", "--pwd=$cleanPWD", "--pswd=$cleanPSWD", "--config=$env:POSH_THEME", "--shell=::SHELL::")) -join "`n" @(Start-Utf8Process $script:OMPExecutable @("print", "debug", "--pwd=$cleanPWD", "--pswd=$cleanPSWD", "--config=$env:POSH_THEME", "--shell=::SHELL::")) -join "`n"
return return
} }
@ -274,7 +274,7 @@ Example:
$stackCount = (Get-Location -Stack).Count $stackCount = (Get-Location -Stack).Count
try { try {
if (Test-Path variable:global:OMP_GLOBAL_SESSIONSTATE) { if (Test-Path Variable:/global:OMP_GLOBAL_SESSIONSTATE) {
$stackCount = $global:OMP_GLOBAL_SESSIONSTATE.Path.LocationStack('').Count $stackCount = $global:OMP_GLOBAL_SESSIONSTATE.Path.LocationStack('').Count
} }
} catch {} } catch {}
@ -309,3 +309,5 @@ Example:
"prompt" "prompt"
) )
} | Import-Module -Global } | Import-Module -Global
function Test-PSDebugContext { return Test-Path Variable:/PSDebugContext }