Skip to content

Add --sort to choose the order of the files to close #792 - #804

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

mathiasrw merged 1 commit into
mainfrom
fix/792

Conversation

@mathiasrw

@mathiasrw mathiasrw commented Oct 23, 2026 •

Copy link
Copy Markdown
Owner

Closes #792

Stacked on #803.

Change

--sort <how> decides the order the files are handled and printed in.

Value Order
natural Numbers as numbers, and case is ignored: file2 before file10, a.md before B.md. The default.
ascii By char code, as before.
none The files given as paths first, in the order given, and then the files found by globs, sorted natural.
modified Oldest first.
created Oldest first. Where the file system does not keep the time a file was made, modified is used, with a 🟡 warning.
size Smallest first.
  • The values can be written in any case, and true and yes are natural. An unknown value, or --sort with no value, stops the run (exit code 3).
  • When two files are the same for the sort, ascii decides.
  • --sort-reverse turns the order around.
  • With --sort or --sort-reverse the files are handled one at a time, so they are printed in the order of the sort. Without it the files are handled at the same time, so the order of the output can not be guaranteed, but the work is started in natural order.
  • The help lists the values as choices, and yargs refuses others (exit code 3).
> ls -t | rexreplace foo bar --glob-pipe --sort none
> rexreplace foo bar '*.log' --sort size --sort-reverse

What breaks

natural is the default, so the order is new: case is ignored and numbers are numbers. --sort ascii gives the order from before.

Speed

natural costs a little more than ascii. The whole command, with Bun on a Mac, 5 runs each, a pattern that finds nothing and -S, so the difference is mostly the sort:

Files --sort ascii --sort natural CPU time added by natural
10,000 247 ms (± 57) 224 ms (± 3) about 13 ms
50,000 1.10 s (± 0.02) 1.32 s (± 0.14) about 110 ms

One file is not sorted at all, so it needs no stat either.

Also in this PR

Two small README edits in "Future ideas": json5 is added to the files that could be required directly, and the idea of an automatic string search is gone.

Tests

yarn test-ci passes: the demo on Node and Bun (with --sort-reverse), and 1010 Bun tests. test/engine/sort.test.js, test/engine/sort-reverse.test.js and test/cli/sort.test.js are new. Three tests and one line in the demo expected the old order, and now expect the natural one.

@mathiasrw
mathiasrw added this pull request to stack #787 October 23, 2026 09:45
@mathiasrw
mathiasrw force-pushed the fix/792 branch 4 times, most recently from eeef6d4 to 354c922 Compare October 23, 2026 10:10
Base automatically changed from fix/795 to main October 23, 2026 10:11
@mathiasrw
mathiasrw marked this pull request as draft October 23, 2026 10:21
@mathiasrw
mathiasrw marked this pull request as ready for review October 23, 2026 10:24
@mathiasrw
mathiasrw marked this pull request as draft October 23, 2026 10:40
@mathiasrw
mathiasrw marked this pull request as ready for review October 23, 2026 10:41
@mathiasrw
mathiasrw marked this pull request as draft October 23, 2026 10:44
@mathiasrw
mathiasrw marked this pull request as ready for review October 23, 2026 10:46
@mathiasrw
mathiasrw merged commit c7ce36e into main Oct 23, 2026
7 checks passed
@mathiasrw
mathiasrw deleted the fix/792 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 --sort to choose the order of the files

1 participant