Skip to content

Add file and match numbers to --js to close #791 - #805

Merged
mathiasrw merged 1 commit into
mainfrom
fix/791
Oct 23, 2026
Merged

mathiasrw merged 1 commit into
mainfrom
fix/791

Conversation

@mathiasrw

Copy link
Copy Markdown
Owner

Closes #791

Stacked on #804.

Change

The code of --js gets numbers. They start at 1.

Variable The number of
$n this file among the files found
$t files found (the total)
$i this file among the files with a match so far
$c this file among the files changed so far
$m this match in this file
$M this match across all files so far

Each has cousins: with zeros in front as a string ($n0 has 2 digits, $n00 3, and so on to $n000000000 with 10), and with a space at the end ($n_, $n00_).

> rexreplace '^.*$' '"photo-" + $n00 + ext' '*.jpg' --rename --js --sort modified
photo-001.jpg
photo-002.jpg
  • The variables are made by code put in front of the code of the user.
  • A run that uses $i, $c, $m or $M handles the files one at a time, in the order of --sort, so the numbers are the same on every run.
  • $m and $M make the code run once per match, like $0 and $1.
  • $i and $c are only different when a match gives the same text: the file has a match, but is not changed.
  • With € the shell does not get in the way: €n00.

Tests

yarn test-ci passes: the demo on Node and Bun (with €n00), and 1016 Bun tests. test/fix/791.test.js is new. Its test with 30 files fails when the run is not made to go one file at a time.

@mathiasrw
mathiasrw added this pull request to stack #787 October 23, 2026 09:45
@mathiasrw
mathiasrw force-pushed the fix/791 branch 5 times, most recently from 5115347 to 9f0f990 Compare October 23, 2026 10:11
Base automatically changed from fix/792 to main October 23, 2026 10:48
@mathiasrw
mathiasrw merged commit 3b8a933 into main Oct 23, 2026
7 checks passed
@mathiasrw
mathiasrw deleted the fix/791 branch October 23, 2026 11:01
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.

Add file and match numbers to --replacement-js

1 participant