Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/WP_CLI/Shell/REPL.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,12 @@
}

private static function create_prompt_cmd( $prompt, $history_path ) {
$prompt = escapeshellarg( $prompt );
$history_path = escapeshellarg( $history_path );
$is_windows = \WP_CLI\Utils\is_windows();

if ( getenv( 'WP_CLI_CUSTOM_SHELL' ) ) {
$shell_binary = (string) getenv( 'WP_CLI_CUSTOM_SHELL' );
} elseif ( $is_windows ) {
$shell_binary = 'powershell.exe';
} elseif ( is_file( '/bin/bash' ) && is_readable( '/bin/bash' ) ) {
// Prefer /bin/bash when available since we use bash-specific commands.
$shell_binary = '/bin/bash';
Expand All @@ -191,10 +193,19 @@
$shell_binary = 'bash';
}

if ( ! is_file( $shell_binary ) || ! is_readable( $shell_binary ) ) {
WP_CLI::error( "The shell binary '{$shell_binary}' is not valid. You can override the shell to be used through the WP_CLI_CUSTOM_SHELL environment variable." );
$is_powershell = $is_windows && 'powershell.exe' === $shell_binary;

if ( $is_powershell ) {
// PowerShell uses ` (backtick) for escaping but for strings single quotes are literal.
// If prompt contains single quotes, we double them in PowerShell.
$prompt_for_ps = str_replace( "'", "''", $prompt );
$cmd = "\$line = Read-Host -Prompt '{$prompt_for_ps}'; Write-Output \$line;";

Check warning on line 202 in src/WP_CLI/Shell/REPL.php

View workflow job for this annotation

GitHub Actions / code-quality / PHPCS

Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space
return "powershell.exe -NoProfile -Command \"{$cmd}\"";
}
Comment on lines +201 to 209

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The new PowerShell implementation provides basic REPL functionality, but it's missing command history support, which is a crucial feature for an interactive shell. The use of Read-Host with the -NoProfile switch on powershell.exe prevents the use of PSReadLine for history. This is a significant usability regression compared to the bash/ksh implementation which explicitly handles a history file.

Please consider implementing history support for PowerShell. This could involve:

  • Manually managing a history file with PowerShell commands (e.g., Get-Content/Add-Content).
  • Interacting with the PSReadLine module's history functions if it's available.

Without history, the shell is much less productive.


$prompt = escapeshellarg( $prompt );
$history_path = escapeshellarg( $history_path );
Comment thread
swissspidy marked this conversation as resolved.

$is_ksh = self::is_ksh_shell( $shell_binary );
$shell_binary = escapeshellarg( $shell_binary );

Expand Down
Loading