refactor(pwsh): pass only non-filesystem path to pswd
Some checks are pending
Code QL / code-ql (push) Waiting to run
Azure Static Web Apps CI/CD / Build and Deploy (push) Waiting to run
Release / changelog (push) Waiting to run
Release / artifacts (push) Blocked by required conditions

This commit is contained in:
L. Yeung 2024-08-06 17:55:39 +08:00 committed by Jan De Dobbeleer
parent 485f45c496
commit 9bcc084787

View file

@ -115,12 +115,11 @@ New-Module -Name "oh-my-posh-core" -ScriptBlock {
function Set-PoshContext([bool]$originalStatus) {} function Set-PoshContext([bool]$originalStatus) {}
function Get-CleanPSWD { function Get-NonFSWD {
$pswd = $PWD.ToString() # We only need to return a non-filesystem working directory.
if ($pswd -ne '/') { if ($PWD.Provider.Name -ne 'FileSystem') {
return $pswd.TrimEnd('\') -replace '^Microsoft\.PowerShell\.Core\\FileSystem::', '' return $PWD.ToString()
} }
return $pswd
} }
function Get-TerminalWidth { function Get-TerminalWidth {
@ -154,10 +153,10 @@ New-Module -Name "oh-my-posh-core" -ScriptBlock {
$script:TooltipCommand = $command $script:TooltipCommand = $command
$column = $Host.UI.RawUI.CursorPosition.X $column = $Host.UI.RawUI.CursorPosition.X
$terminalWidth = Get-TerminalWidth $terminalWidth = Get-TerminalWidth
$cleanPSWD = Get-CleanPSWD $nonFSWD = Get-NonFSWD
$stackCount = global:Get-PoshStackCount $stackCount = global:Get-PoshStackCount
$standardOut = (Start-Utf8Process $global:_ompExecutable @("print", "tooltip", "--status=$script:ErrorCode", "--shell=$script:ShellName", "--pswd=$cleanPSWD", "--execution-time=$script:ExecutionTime", "--stack-count=$stackCount", "--command=$command", "--shell-version=$script:PSVersion", "--column=$column", "--terminal-width=$terminalWidth", "--no-status=$script:NoExitCode", "--job-count=$script:JobCount")) -join '' $standardOut = (Start-Utf8Process $global:_ompExecutable @("print", "tooltip", "--status=$script:ErrorCode", "--shell=$script:ShellName", "--pswd=$nonFSWD", "--execution-time=$script:ExecutionTime", "--stack-count=$stackCount", "--command=$command", "--shell-version=$script:PSVersion", "--column=$column", "--terminal-width=$terminalWidth", "--no-status=$script:NoExitCode", "--job-count=$script:JobCount")) -join ''
if (!$standardOut) { if (!$standardOut) {
return return
} }
@ -333,10 +332,10 @@ New-Module -Name "oh-my-posh-core" -ScriptBlock {
$themes | Select-Object @{ Name = 'hyperlink'; Expression = { Get-FileHyperlink -uri $_.FullName } } | Format-Table -HideTableHeaders $themes | Select-Object @{ Name = 'hyperlink'; Expression = { Get-FileHyperlink -uri $_.FullName } } | Format-Table -HideTableHeaders
} }
else { else {
$cleanPSWD = Get-CleanPSWD $nonFSWD = Get-NonFSWD
$themes | ForEach-Object -Process { $themes | ForEach-Object -Process {
Write-Host "Theme: $(Get-FileHyperlink -uri $_.FullName -Name ($_.BaseName -replace '\.omp$', ''))`n" Write-Host "Theme: $(Get-FileHyperlink -uri $_.FullName -Name ($_.BaseName -replace '\.omp$', ''))`n"
Start-Utf8Process $global:_ompExecutable @("print", "primary", "--config=$($_.FullName)", "--pswd=$cleanPSWD", "--shell=$script:ShellName") Start-Utf8Process $global:_ompExecutable @("print", "primary", "--config=$($_.FullName)", "--pswd=$nonFSWD", "--shell=$script:ShellName")
Write-Host "`n" Write-Host "`n"
} }
} }
@ -446,7 +445,7 @@ Example:
Set-PoshContext $script:ErrorCode Set-PoshContext $script:ErrorCode
$cleanPSWD = Get-CleanPSWD $nonFSWD = Get-NonFSWD
$stackCount = global:Get-PoshStackCount $stackCount = global:Get-PoshStackCount
$terminalWidth = Get-TerminalWidth $terminalWidth = Get-TerminalWidth
@ -454,7 +453,7 @@ Example:
$env:POSH_CURSOR_LINE = $Host.UI.RawUI.CursorPosition.Y + 1 $env:POSH_CURSOR_LINE = $Host.UI.RawUI.CursorPosition.Y + 1
$env:POSH_CURSOR_COLUMN = $Host.UI.RawUI.CursorPosition.X + 1 $env:POSH_CURSOR_COLUMN = $Host.UI.RawUI.CursorPosition.X + 1
$standardOut = Start-Utf8Process $global:_ompExecutable @("print", $script:PromptType, "--status=$script:ErrorCode", "--pswd=$cleanPSWD", "--execution-time=$script:ExecutionTime", "--stack-count=$stackCount", "--shell-version=$script:PSVersion", "--terminal-width=$terminalWidth", "--shell=$script:ShellName", "--no-status=$script:NoExitCode", "--job-count=$script:JobCount") $standardOut = Start-Utf8Process $global:_ompExecutable @("print", $script:PromptType, "--status=$script:ErrorCode", "--pswd=$nonFSWD", "--execution-time=$script:ExecutionTime", "--stack-count=$stackCount", "--shell-version=$script:PSVersion", "--terminal-width=$terminalWidth", "--shell=$script:ShellName", "--no-status=$script:NoExitCode", "--job-count=$script:JobCount")
# make sure PSReadLine knows if we have a multiline prompt # make sure PSReadLine knows if we have a multiline prompt
Set-PSReadLineOption -ExtraPromptLineCount (($standardOut | Measure-Object -Line).Lines - 1) Set-PSReadLineOption -ExtraPromptLineCount (($standardOut | Measure-Object -Line).Lines - 1)