kkinnear / zprint

Executables, uberjar, and library to beautifully format Clojure and Clojurescript source code and s-expressions.
MIT License
554 stars 47 forks source link

how do I to check or write all files recurisvely in a folder? #293

Closed drewverlee closed 1 year ago

drewverlee commented 1 year ago

zprint '{:style :community}' -w *.clj

Doesn't seem to find all files recursively.

kkinnear commented 1 year ago

Thanks for asking!

Yes, the prebuilt zprint binaries only process the files supplied by the shell. They don't know anything about directories or anything -- they just get a bunch of full file specs from the shell and process those. Your normal shell doesn't do *.clj recursively, it just looks in the current directory.

That said, if you want to process all of the *.clj files in the current directory and all of the directories below, I think one option would be to use the find program. Something like this might do what you want:

./zprintm-1.2.5 -lfsc `find . -name "*.clj"`

I did this in the project directory for zprint, and it ended up with:

...
Formatting required in file ./znew1.clj
Processing file ./zc1.clj
Processing file ./src/zprint/repl.clj
Formatting required in file ./src/zprint/repl.clj
Processing file ./src/zprint/replbb.clj
Formatting required in file ./src/zprint/replbb.clj
Processed 670 files, with 14 errors, 543 of which require formatting.

There are certainly other ways to use find, in particular it has -exec where you can give zprint as an argument to find itself.

I did some searching and there is another way that also seems like it might work and is a bit simpler, which was actually news to me.

Apparently the syntax **/*.clj will tell some shells to recursively look down and return all of those files. Thus:

echo **/*.clj

will produce a list of files that would also be useable if you just did:

./zprintm-1.2.5 -lfsc **/*.clj

This works on macOS Ventura, and probably previous versions since they've gone to zsh.

I hope that this helps!