Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 8 additions & 12 deletions php/WP_CLI/REPL.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,14 @@ private static function create_prompt_cmd( $prompt, $history_path ) {
$prompt = escapeshellarg( $prompt );
$history_path = escapeshellarg( $history_path );

$cmd = <<<BASH
set -f
history -r $history_path
LINE=""
read -re -p $prompt LINE
[ $? -eq 0 ] || exit
history -s "\$LINE"
history -w $history_path
echo \$LINE
BASH;

$cmd = str_replace( "\n", '; ', $cmd );
$cmd = "set -f; "
. "history -r $history_path; "
. "LINE=\"\"; "
. "read -re -p $prompt LINE; "
. "[ $? -eq 0 ] || exit; "
. "history -s \"\$LINE\"; "
. "history -w $history_path; "
. "echo \$LINE; ";

return '/bin/bash -c ' . escapeshellarg( $cmd );
}
Expand Down
2 changes: 1 addition & 1 deletion php/commands/shell.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __invoke( $_, $assoc_args ) {
if ( '\\Psy\\Shell' == $class ) {
\Psy\Shell::debug();
} else {
$repl = new $class( 'wp> ' );
$repl = new $class( "\nwp> " );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@JRGould I noticed this adds a newline when the shell first begins too. Is there a way of preventing this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Could probably add a flag to \WP_CLI\REPL and strip out the newline just the first time the prompt is printed. Not sure about Psy or Boris though. Happy to open another issue/PR for that if you think it's worth the tinker?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Happy to open another issue/PR for that if you think it's worth the tinker?

Yes please. We should also look into whether we can inject the newline after command execution.

$repl->start();
}
}
Expand Down