From a31d718fcbef4382e150d71c0de0508765ae5ecd Mon Sep 17 00:00:00 2001 From: lnu Date: Thu, 7 Apr 2022 08:44:17 +0200 Subject: [PATCH] fix(pwsh): call convert-path before setting workingdirectory Only for FileSystem psprovider --- src/shell/scripts/omp.ps1 | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/shell/scripts/omp.ps1 b/src/shell/scripts/omp.ps1 index edf60ba0..abfdff26 100644 --- a/src/shell/scripts/omp.ps1 +++ b/src/shell/scripts/omp.ps1 @@ -1,26 +1,27 @@ -function global:Start-Utf8Process -{ - param( +function global:Start-Utf8Process { + param( [string] $FileName, [string] $Arguments ) - $Process = New-Object System.Diagnostics.Process - $StartInfo = $Process.StartInfo - $StartInfo.StandardErrorEncoding = $StartInfo.StandardOutputEncoding = [System.Text.Encoding]::UTF8 - $StartInfo.RedirectStandardError = $StartInfo.RedirectStandardInput = $StartInfo.RedirectStandardOutput = $true - $StartInfo.FileName = $filename - $StartInfo.Arguments = $Arguments + $Process = New-Object System.Diagnostics.Process + $StartInfo = $Process.StartInfo + $StartInfo.StandardErrorEncoding = $StartInfo.StandardOutputEncoding = [System.Text.Encoding]::UTF8 + $StartInfo.RedirectStandardError = $StartInfo.RedirectStandardInput = $StartInfo.RedirectStandardOutput = $true + $StartInfo.FileName = $filename + $StartInfo.Arguments = $Arguments $StartInfo.UseShellExecute = $false - $StartInfo.WorkingDirectory = $PWD #when UseShellExecute=false, workingDirectory="" + if ($pwd.provider.name -eq "FileSystem") { #workingdirectory does not work with registry path + $StartInfo.WorkingDirectory = convert-path $pwd #when UseShellExecute=false, workingDirectory="" + } $StartInfo.CreateNoWindow = $true - $_ = $Process.Start(); - $_ = $Process.WaitForExit(); + $_ = $Process.Start(); + $_ = $Process.WaitForExit(); $stderr = $Process.StandardError.ReadToEnd().Trim() if ($stderr -ne '') { $Host.UI.WriteErrorLine($stderr) } - return $Process.StandardOutput.ReadToEnd() + return $Process.StandardOutput.ReadToEnd() } $env:POWERLINE_COMMAND = "oh-my-posh" @@ -192,7 +193,8 @@ function global:Enable-PoshTransientPrompt { [Console]::OutputEncoding = [Text.Encoding]::UTF8 try { [Microsoft.PowerShell.PSConsoleReadLine]::InvokePrompt() - } finally { + } + finally { [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine() [Console]::OutputEncoding = $previousOutputEncoding }