Skip to content

Add ksh support for OpenBSD (and mksh/pdksh)#87

Open
Copilot wants to merge 3 commits intomainfrom
copilot/add-support-for-ksh-openbsd
Open

Add ksh support for OpenBSD (and mksh/pdksh)#87
Copilot wants to merge 3 commits intomainfrom
copilot/add-support-for-ksh-openbsd

Conversation

Copy link
Contributor

Copilot AI commented Mar 15, 2026

wp shell fails immediately on OpenBSD because the REPL's prompt command uses bash-specific builtins (read -e, read -p, history -r/-s/-w) that ksh does not support.

Changes

  • is_ksh_shell() — detects ksh-compatible shells by binary basename (ksh, ksh93, ksh88, mksh, pdksh)
  • is_supported_shell() — helper combining bash + ksh checks; used by the $SHELL env-var fallback so OpenBSD users with SHELL=/bin/ksh no longer need to set WP_CLI_CUSTOM_SHELL
  • ksh command path in create_prompt_cmd() — when a ksh shell is detected, replaces bash-specific flags with POSIX equivalents; history is skipped (unavailable in non-interactive ksh mode):
# bash path (unchanged)
read -re -p 'wp> ' LINE; history -s -- "$LINE"; history -w /path/to/history; ...

# new ksh path
printf %s 'wp> ' >&2; IFS= read -r LINE || exit; printf '%s\n' "$LINE";

The prompt is written to stderr so it remains visible to the user without being captured by popen.

Original prompt

This section details on the original issue you should resolve

<issue_title>Feature request: support ksh under OpenBSD</issue_title>
<issue_description>## Feature Request

Add support for default shell on OpenBSD (ksh).

Describe your use case and the problem you are facing

Trying to use wp shell cmd under OpenBSD results in errors and exits prematurely.

$ wp shell
/bin/ksh: fc: history functions not available
/bin/ksh: read: -e: unknown option
$ echo $?
0

$ wp cli info
OS:     OpenBSD 6.6 GENERIC.MP#584 amd64
Shell:  /bin/ksh
PHP binary:     /usr/local/bin/php-7.3
PHP version:    7.3.13
php.ini used:   /etc/php-7.3.ini
WP-CLI root dir:        phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:      phar://wp-cli.phar/vendor
WP_CLI phar path:       /var/www/htdocs
WP-CLI packages dir:
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 2.4.0
$ env | grep WP_CLI_CUSTOM_SHELL
WP_CLI_CUSTOM_SHELL=/bin/ksh

Describe the solution you'd like

Quick win:

Add some more detection at shell instantiation to detect shell and platform to enable running in ksh on OpenBSD.

Nice to have:

Test in a few different shell/OS environments and modify to run across more - else, fail gracefully when unsupported.

Happy to work on this</issue_description>

Comments on the Issue (you are @copilot in this section)

@danielbachhuber Thanks for the report, @leonstafford !

It looks like you're actually passing WP_CLI_CUSTOM_SHELL=/bin/ksh correctly. The problem is that this series of commands are failing:

$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; ';

Do you know what it would take to rewrite this for compatibility with /bin/ksh?


📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

@codecov
Copy link

codecov bot commented Mar 15, 2026

Codecov Report

❌ Patch coverage is 64.00000% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/WP_CLI/Shell/REPL.php 64.00% 9 Missing ⚠️

📢 Thoughts on this report? Let us know!

…ands

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for default shell ksh under OpenBSD Add ksh support for OpenBSD (and mksh/pdksh) Mar 15, 2026
Copilot AI requested a review from swissspidy March 15, 2026 13:33
@swissspidy swissspidy marked this pull request as ready for review March 15, 2026 18:48
@swissspidy swissspidy requested a review from a team as a code owner March 15, 2026 18:48
Copilot AI review requested due to automatic review settings March 15, 2026 18:48
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds ksh compatibility to the built-in wp shell --basic REPL so it can run on OpenBSD (and similar environments) where /bin/ksh is the default and bash-specific read/history builtins are unavailable.

Changes:

  • Add ksh-family shell detection (is_ksh_shell()) and a combined is_supported_shell() helper.
  • Expand $SHELL fallback to accept supported shells (bash or ksh-family) instead of bash-only.
  • Introduce a ksh-specific prompt command path using POSIX read and printing the prompt to stderr (skipping history).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: support ksh under OpenBSD

3 participants