From 57cf9b8363c89bd094a6473f588fe0710edc65fb Mon Sep 17 00:00:00 2001 From: Lucas Trzesniewski Date: Mon, 9 Feb 2026 07:25:06 +0100 Subject: fix(powershell): display search stderr (#3146) This shows stderr output from `atuin search -i` in PowerShell: The output looks like this: image Currently reproducible with the following config: ```toml [keymap.emacs] "foo" = "bar" "=" = "bar" ``` I started by using `Start-Process` in the first commit, but then rewrote it entirely as using a `Process` object directly should be more stable (`Start-Process` already [caused issues](https://github.com/atuinsh/atuin/pull/2543#issuecomment-2647555114) in the past). This fixes the PowerShell part of #3134 ## Checks - [x] I am happy for maintainers to push small adjustments to this PR, to speed up the review cycle - [x] I have checked that there are no existing pull requests for the same thing --- crates/atuin/src/shell/atuin.ps1 | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/crates/atuin/src/shell/atuin.ps1 b/crates/atuin/src/shell/atuin.ps1 index 33c2ba5f..7f6ad8cf 100644 --- a/crates/atuin/src/shell/atuin.ps1 +++ b/crates/atuin/src/shell/atuin.ps1 @@ -135,16 +135,40 @@ New-Module -Name Atuin -ScriptBlock { $previousOutputEncoding = [System.Console]::OutputEncoding $resultFile = New-TemporaryFile + $suggestion = "" + $errorOutput = "" try { [System.Console]::OutputEncoding = [System.Text.Encoding]::UTF8 - # Atuin is started through Start-Process to avoid interfering with the current shell. - $env:ATUIN_SHELL = "powershell" - $env:ATUIN_QUERY = Get-CommandLine - $argString = "search -i --result-file ""$resultFile"" $ExtraArgs" - Start-Process -PassThru -NoNewWindow -FilePath atuin -ArgumentList $argString | Wait-Process - $suggestion = (Get-Content -Raw $resultFile -Encoding UTF8 | Out-String).Trim() + # Start-Process does some crazy stuff, just use the Process class directly to have more control. + $process = New-Object System.Diagnostics.Process + $process.StartInfo.FileName = "atuin" + $process.StartInfo.Arguments = "search -i --result-file ""$resultFile"" $ExtraArgs" + $process.StartInfo.UseShellExecute = $false + $process.StartInfo.RedirectStandardError = $true + $process.StartInfo.StandardErrorEncoding = [System.Text.Encoding]::UTF8 + $process.StartInfo.EnvironmentVariables["ATUIN_SHELL"] = "powershell" + $process.StartInfo.EnvironmentVariables["ATUIN_QUERY"] = Get-CommandLine + + try { + $process.Start() | Out-Null + + # A single stream is redirected, so we can read it synchronously, but we have to start reading it + # before waiting for the process to exit, otherwise the buffer could fill up and cause a deadlock. + $errorOutput = $process.StandardError.ReadToEnd().Trim() + $process.WaitForExit() + + $suggestion = (Get-Content -Raw $resultFile -Encoding UTF8 | Out-String).Trim() + } + catch { + $errorOutput = $_ + } + + if ($errorOutput) { + Write-Host -ForegroundColor Red "Atuin error:" + Write-Host -ForegroundColor DarkRed $errorOutput + } # If no shell prompt offset is set, initialize it from the current prompt line count. if ($null -eq $env:ATUIN_POWERSHELL_PROMPT_OFFSET) { @@ -179,8 +203,6 @@ New-Module -Name Atuin -ScriptBlock { } finally { [System.Console]::OutputEncoding = $previousOutputEncoding - $env:ATUIN_SHELL = $null - $env:ATUIN_QUERY = $null Remove-Item $resultFile } } -- cgit v1.3.1