From 7e7d76bf3652392a2bc729827b19713852f75324 Mon Sep 17 00:00:00 2001 From: drcxd Date: Wed, 26 Nov 2025 16:34:37 +0800 Subject: [PATCH] Update pwsh profile so that it does not err on batch mode * pwsh/Microsoft.PowerShell_profile.ps1 (Function): Only set several PSReadline options when PowerShell is used interactively. --- pwsh/Microsoft.PowerShell_profile.ps1 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pwsh/Microsoft.PowerShell_profile.ps1 b/pwsh/Microsoft.PowerShell_profile.ps1 index c19121a..80ebcf1 100644 --- a/pwsh/Microsoft.PowerShell_profile.ps1 +++ b/pwsh/Microsoft.PowerShell_profile.ps1 @@ -34,8 +34,13 @@ Set-PSReadLineOption ` 'git status', 'git diff', 'git diff --staged', 'git log' } if (-not ($Host.UI.RawUI.WindowSize.Width -lt 54 -or $Host.UI.RawUI.WindowSize.Height -lt 15)) { - Set-PSReadLineOption -PredictionViewStyle ListView - Set-PSReadlineKeyHandler -Key Escape -Function Undo + if ([Environment]::UserInteractive -and + $Host.Name -eq 'ConsoleHost' -and + -not [Console]::IsInputRedirected -and + -not [Console]::IsOutputRedirected) { + Set-PSReadLineOption -PredictionViewStyle ListView + Set-PSReadlineKeyHandler -Key Escape -Function Undo + } } Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward