Skip to content

Commit a1c89c5

Browse files
Copilotswissspidy
andauthored
Fix PowerShell detection to use case-insensitive basename and support pwsh.exe; use $shell_binary in command
Agent-Logs-Url: https://github.com/wp-cli/shell-command/sessions/90c60f97-7618-4f00-b033-38616307478c Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 6b8b34d commit a1c89c5

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/WP_CLI/Shell/REPL.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,17 @@ private static function create_prompt_cmd( $prompt, $history_path ) {
195195
$shell_binary = 'bash';
196196
}
197197

198-
$is_powershell = $is_windows && 'powershell.exe' === $shell_binary;
198+
$shell_basename = strtolower( basename( $shell_binary ) );
199+
$is_powershell = $is_windows && in_array( $shell_basename, array( 'powershell.exe', 'pwsh.exe' ), true );
199200

200201
if ( $is_powershell ) {
201202
// PowerShell uses ` (backtick) for escaping but for strings single quotes are literal.
202203
// If prompt contains single quotes, we double them in PowerShell.
203204
$prompt_for_ps = str_replace( "'", "''", $prompt );
204205
$history_path_for_ps = str_replace( "'", "''", $history_path );
205206
$cmd = "\$line = Read-Host -Prompt '{$prompt_for_ps}'; if ( \$line ) { Add-Content -Path '{$history_path_for_ps}' -Value \$line; } Write-Output \$line;";
206-
return "powershell.exe -Command \"{$cmd}\"";
207+
$shell_quoted = escapeshellarg( $shell_binary );
208+
return "{$shell_quoted} -Command \"{$cmd}\"";
207209
}
208210

209211
if ( ! is_file( $shell_binary ) || ! is_readable( $shell_binary ) ) {

0 commit comments

Comments
 (0)