Bookmarks with shell glob patterns fail — spawnShellCommand uses /bin/sh instead of user's shell

Open Beginner friendly
#35 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Domain
cli

Research direction

Start in index.js at spawnShellCommand around lines 53–54, then reproduce the bookmark examples from the issue with the :or and :brace render modes. Done means those commands execute with the appropriate user shell and retain the documented fallback when $SHELL is unset.

Written by the indexing model from the issue text.

Description

Bookmark commands that contain shell-specific glob or expansion syntax fail at runtime because spawnShellCommand uses /bin/sh (POSIX sh) via Node.js spawnSync(..., { shell: true }).

POSIX sh doesn't support:

Extended glob alternation: (a|b|c) (zsh)
Brace expansion: {a,b,c} (bash/zsh)
This means the :or and :brace array render modes in wildcards produce output that can never actually execute successfully.

Repro

scriptpal bookmark add demo 'echo packages/(foo|bar|baz)'
scriptpal bookmark run demo
# /bin/sh: -c: line 0: syntax error near unexpected token `|'

Or using the :or wildcard renderer:

scriptpal bookmark add typecheck 'yarn typecheck:package packages/${pkg:array:or}'
scriptpal bookmark run typecheck pkg=foo,bar
# /bin/sh: -c: line 0: syntax error near unexpected token `|'

Root cause

// index.js line 53-54
function spawnShellCommand(command) {
  const result = spawnSync(command, { stdio: "inherit", shell: true });

When shell: true, Node.js defaults to /bin/sh on Unix. /bin/sh is POSIX-only and rejects the syntax that :or and :brace renderers produce.

Proposed fix
Use the user's login shell ($SHELL) instead of the default:

function spawnShellCommand(command) {
  const result = spawnSync(command, {
    stdio: "inherit",
    shell: process.env.SHELL || true,
  });

When the shell option is a string, Node.js uses that binary. This means:

zsh users get (a|b) extended glob support
bash users get {a,b} brace expansion support
Falls back to the default /bin/sh if $SHELL is unset

Dominant language
JavaScript
Stars
13
Forks
0
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from danieldelcore/scriptpal

All issues in danieldelcore/scriptpal

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.