aboutsummaryrefslogtreecommitdiffstats
path: root/crates
diff options
context:
space:
mode:
authorLucas Trzesniewski <lucas.trzesniewski@gmail.com>2026-02-09 07:25:06 +0100
committerGitHub <noreply@github.com>2026-02-08 22:25:06 -0800
commit57cf9b8363c89bd094a6473f588fe0710edc65fb (patch)
treea3349a6d3c9531345ce95bf6766e65c88c6d3069 /crates
parentfix: remove invalid IF EXISTS from sqlite drop column migration (#3145) (diff)
downloadatuin-57cf9b8363c89bd094a6473f588fe0710edc65fb.zip
fix(powershell): display search stderr (#3146)
This shows stderr output from `atuin search -i` in PowerShell: The output looks like this: <img width="628" height="149" alt="image" src="https://github.com/user-attachments/assets/c0a4bc9a-5d57-415f-a5b4-9c497744c6e0" /> 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
Diffstat (limited to 'crates')
-rw-r--r--crates/atuin/src/shell/atuin.ps138
1 files 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
}
}