Skip to content

feat(builtins): add parallel command (non-standard, GNU parallel-lite) #570

@chaliy

Description

@chaliy

Summary

A non-standard builtin for parallel command execution, inspired by GNU parallel and xargs -P. Even without true background & support, a dedicated parallel builtin could use tokio internally to run multiple commands concurrently.

Proposed Syntax

parallel [OPTIONS] command [:::] [args...]
# or
input | parallel [OPTIONS] command

Proposed Flags

Flag Description
-j N Max concurrent jobs (default: 4)
--arg {} Placeholder for input (default: {})
-k Keep output order (match input order)
--dry-run Print commands without executing
--bar Show progress to stderr
--halt now,fail=1 Stop on first failure
--halt soon,fail=1 Finish running, fail if any failed

Use Cases

# Process files in parallel
find . -name '*.json' | parallel -j 4 'jq .name {}'

# Parallel curl
echo -e "url1\nurl2\nurl3" | parallel -j 3 'curl -s {} > {}.html'

# With ::: argument list (no pipe needed)
parallel echo ::: a b c d

# Ordered output
seq 10 | parallel -k -j 4 'sleep $((RANDOM % 3)); echo {}'

# Transform files
ls *.csv | parallel -j 2 'csv to-json < {} > {.}.json'

llm_hint()

Some("parallel: Run commands concurrently. `ls *.txt | parallel -j 4 'wc -l {}'`. Like xargs -P but simpler.")

Implementation Notes

  • Internally uses tokio::spawn to run interpreter instances concurrently
  • Each job gets a cloned interpreter (like subshell)
  • {} is replaced with the input line; {.} strips extension; {/} basename
  • Output buffered per job, printed atomically (no interleaving)
  • -k ensures output order matches input order
  • Resource limits shared across all jobs (total commands, output size)
  • This is an alternative to full background & support (feat(interpreter): real background execution with & and wait #559) — can be implemented independently

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions