XAMPPRocky / tokei

Count your code, quickly.
Other
10.56k stars 507 forks source link

[Feature Request] Add flag to show output by top-level folder #676

Open camelid opened 3 years ago

camelid commented 3 years ago

I have a Cargo workspace and I would like to see LOC per folder in my src directory. I could write a shell script, but it would be nice to have support for that in Tokei itself. There is already a --files option, but that shows per-file and not per-folder.

Perhaps it could be something like tokei src --folders and then it would output information for each top-level folder (and maybe top-level file) in src.

XAMPPRocky commented 3 years ago

Thank you for your issue! I'm quite hesitant about adding such a feature, as while you're asking --folders to output the top level folders, there have been people over the years who have asked for a recursive version, and I've rejected for the same reason; which is that is that can be hard to infer what you expect the output to be from just --folders. I think I would be more amenable to making it easier to accept stdin for input paths so that it be easier to work with existing tools like ls and find, and write one-liners. For example I think it would be nice if tokei accepted - as "read paths from stdin". So that you could write the following to achieve what you want.

ls -d src/*/ | tokei -
camelid commented 3 years ago

Sure, as long as there's a simple way to do it :)

The one problem with having tokei - mean read paths from stdin is that you wouldn't be able to in the future have tokei - take code as input in stdin. But at that point maybe tokei doesn't give you a ton of advantage over wc? Though if you added a -l or -t option to set the language of the input then you would get the advantage of tokei's semantic information. But maybe that's out of scope; either way there's probably some way you could extend tokei to treat stdin as the input code in the future if you wanted to.