Skip to content

Conversation

@wolfv
Copy link
Member

@wolfv wolfv commented Feb 6, 2025

I am looking into two issues:

{1..5} should expand to 1 2 3 4 5, also in word parts. This already works for globs in deno-task-shell, so it's an extension. Should follow the rules of bash (first brace extension, then globs, for example).

"linux-64" == linux* should use pattern matching (and not glob expansion). If a glob is detected on the right hand side of a binary operation like this, then it's used as a pattern to evaluate against the string on the left hand side. We can just use the glob that is already in use for this, but we need to prevent the current expansion and return a pattern.

wolfv pushed a commit that referenced this pull request Nov 11, 2025
This commit adds brace expansion support to the shell, implementing
a strict subset of bash's brace expansion functionality.

Supported features:
- Comma-separated lists: {a,b,c} → a b c
- Numeric sequences: {1..10} → 1 2 3 4 5 6 7 8 9 10
- Character sequences: {a..z} → a b c ... z
- Reverse sequences: {10..1} → 10 9 8 7 6 5 4 3 2 1
- Step sequences: {1..10..2} → 1 3 5 7 9
- Reverse step sequences: {10..1..2} → 10 8 6 4 2
- Empty elements: {a,,b} → a  b
- Quoted braces don't expand: "{a,b,c}" → {a,b,c}

Implementation details:
- Added BRACE_EXPANSION grammar rule to grammar.pest
- Added BraceExpansion enum to parser.rs with List and Sequence variants
- Added WordPart::BraceExpansion variant
- Implemented expand_braces() and expand_sequence() functions
- Added comprehensive test suite in brace_expansion.sh

The implementation is a strict subset of bash, ensuring compatibility
while keeping the implementation simple and maintainable.

Fixes #242
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant