danieldelcore / danieldelcore/scriptpal

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

Aperta Adatta ai principianti
#35 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
JavaScript
Stelle
13
Fork
0
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Inizia in index.js, presso spawnShellCommand intorno alle righe 53–54, quindi riproduci gli esempi di segnalibri dell’issue con le modalità di rendering :or e :brace. Il lavoro è completato quando quei comandi vengono eseguiti con la shell appropriata dell’utente e mantengono il fallback documentato quando $SHELL non è impostato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, node.js, shell
Ambito
cli
Tipo di issue
Bug
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Tranquilla
Chiarezza
Specificata chiaramente
Idoneità per principianti
76/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.