Skip to content

backticks: implement brace expansion in command literals#61559

Draft
StefanKarpinski wants to merge 3 commits intomasterfrom
sk/backticks-brace-expansion
Draft

backticks: implement brace expansion in command literals#61559
StefanKarpinski wants to merge 3 commits intomasterfrom
sk/backticks-brace-expansion

Conversation

@StefanKarpinski
Copy link
Copy Markdown
Member

Summary

Implement bash-style brace expansion in backtick Cmd syntax, building on top of #61540.

Comma expansion: {a,b,c} expands to three separate arguments, and brace groups participate in the existing arg_gen Cartesian product logic, so `pre{a,b}.{x,y}suf` produces all four combinations. Alternatives support $ interpolation, quoting, and escape sequences. Braces without a comma ({a}, {}) are treated as literal characters, matching bash semantics. Unquoted whitespace inside braces is an error, following zsh.

Range expansion: {1..10} expands to "1" through "10", {a..z} to "a" through "z". Stepped ranges ({1..10..2}) and zero-padded ranges ({01..10}) are supported. Zero-padding pads to the total width of the wider endpoint (matching bash/zsh), so {-03..3} produces "-03" through "003".

Differences from bash/zsh

  • Cross-case character ranges ({a..Z}, {A..z}) are an error rather than iterating through non-letter ASCII characters between Z and a.
  • An explicit + sign on integer endpoints ({-2..+3}) causes non-negative values to be prefixed with +. This is a Julia-specific extension; bash/zsh do not support it.

This PR was written with the assistance of generative AI.

Test plan

  • Comprehensive unit tests for comma expansion, range expansion, zero-padding, negative numbers, + signs, cross-case errors, and invalid range errors.
  • Shell mode end-to-end tests verify brace expansion works through the REPL shell_parsecmd_gen path.

StefanKarpinski and others added 3 commits April 10, 2026 16:30
Implement `|`, `<`, `>`, `>>`, `2>`, `2>>`, `1>`, and `0<` operators
in backtick command literals. These lower to `pipeline()` calls at
parse time, so `` `ls | sort > out.txt` `` works as expected.

Fd-prefixed redirects (`2>`, `1>`, `0<`) require an unquoted integer
before the operator — quoted integers like `'2'>file` are treated as
regular arguments, matching POSIX shell behavior.

The REPL shell mode is updated to handle pipeline/redirect commands,
which previously failed with a `MethodError` on `length(::OrCmds)`.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Implement bash-style brace expansion in backtick Cmd syntax.
`{a,b,c}` expands to three separate arguments, and brace groups
participate in the existing Cartesian product logic so that
`pre{a,b}.{x,y}suf` produces all four combinations. Alternatives
support `$` interpolation, quoting, and escape sequences. Braces
without a comma (`{a}`, `{}`) are treated as literal characters,
matching bash semantics.

Unquoted whitespace inside braces is an error, following zsh.
Quoted spaces like `{"a b",c}` work as expected.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add support for bash-style brace range expansion: `{1..10}` expands
to arguments "1" through "10", `{a..z}` to "a" through "z". Stepped
ranges (`{1..10..2}`) and zero-padded ranges (`{01..10}`) are also
supported. Ranges participate in the existing Cartesian product logic,
so `file{1..3}.{c,h}` produces all six combinations.

Zero-padding pads to the total width of the wider endpoint (matching
bash/zsh), so `{-03..3}` produces "-03" through "003" (width 3).

Invalid range syntax (e.g. `{a..1}` mixing letters and numbers)
produces a parse-time error.

Differences from bash/zsh:

 - Cross-case character ranges (`{a..Z}`, `{A..z}`) are an error
   rather than iterating through non-letter ASCII characters.

 - An explicit `+` sign on integer endpoints (`{-2..+3}`) causes
   non-negative values to be prefixed with `+`. This is a
   Julia-specific extension; bash/zsh do not support it.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@StefanKarpinski StefanKarpinski force-pushed the sk/backticks-redirects branch 3 times, most recently from 33b8361 to ad10b28 Compare April 11, 2026 16:33
Base automatically changed from sk/backticks-redirects to master April 11, 2026 21:25
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