@@ -63,29 +63,21 @@ New-Module -Name Atuin -ScriptBlock {
63
63
function RunSearch {
64
64
param ([string ]$ExtraArgs = " " )
65
65
66
- $line = $null
67
- [Microsoft.PowerShell.PSConsoleReadLine ]::GetBufferState([ref ]$line , [ref ]$null )
68
-
69
- # Atuin is started through Start-Process to avoid interfering with the current shell,
70
- # and to capture its output which is provided in stderr (redirected to a temporary file).
71
-
72
- $suggestion = " "
66
+ $previousOutputEncoding = [System.Console ]::OutputEncoding
73
67
$resultFile = New-TemporaryFile
74
- try {
75
- $env: ATUIN_SHELL_POWERSHELL = " true"
76
- $argString = " search -i $ExtraArgs -- $line "
77
- Start-Process - Wait - NoNewWindow - RedirectStandardError $resultFile.FullName - FilePath atuin - ArgumentList $argString
78
- $suggestion = (Get-Content - Raw $resultFile - Encoding UTF8 | Out-String ).Trim()
79
- }
80
- finally {
81
- $env: ATUIN_SHELL_POWERSHELL = $null
82
- Remove-Item $resultFile
83
- }
84
68
85
- $previousOutputEncoding = [System.Console ]::OutputEncoding
86
69
try {
87
70
[System.Console ]::OutputEncoding = [System.Text.Encoding ]::UTF8
88
71
72
+ $line = $null
73
+ [Microsoft.PowerShell.PSConsoleReadLine ]::GetBufferState([ref ]$line , [ref ]$null )
74
+
75
+ # Atuin is started through Start-Process to avoid interfering with the current shell.
76
+ $env: ATUIN_SHELL_POWERSHELL = " true"
77
+ $argString = " search -i --result-file "" $resultFile "" $ExtraArgs -- $line "
78
+ Start-Process - Wait - NoNewWindow - FilePath atuin - ArgumentList $argString
79
+ $suggestion = (Get-Content - Raw $resultFile - Encoding UTF8 | Out-String ).Trim()
80
+
89
81
# PSReadLine maintains its own cursor position, which will no longer be valid if Atuin scrolls the display in inline mode.
90
82
# Fortunately, InvokePrompt can receive a new Y position and reset the internal state.
91
83
[Microsoft.PowerShell.PSConsoleReadLine ]::InvokePrompt($null , $Host.UI.RawUI.CursorPosition.Y + [int ]$env: ATUIN_POWERSHELL_PROMPT_OFFSET )
@@ -108,6 +100,8 @@ New-Module -Name Atuin -ScriptBlock {
108
100
}
109
101
finally {
110
102
[System.Console ]::OutputEncoding = $previousOutputEncoding
103
+ $env: ATUIN_SHELL_POWERSHELL = $null
104
+ Remove-Item $resultFile
111
105
}
112
106
}
113
107
0 commit comments