Unix tool count lines of code




















Hastur: It runs wc -l for groups of files, rather like xargs does, but it handles odd-ball characters like spaces in file names without needing either xargs or the non-standard -print0 and -0 options to find and xargs respectively. It's a minor optimization. The downside would be that each invocation of wc would output a total line count at the end when given multiple files — the awk script would have deal with that. JonathanLeffler Thank you. I agree.

My concerns, however, were about the length of the parameter string passed to wc. If unknown a priori the number of files that will be found , is there the risk to pass that limit or somehow is it handled by find?

Hastur: find groups the files into convenient size bundles, which won't exceed the length limit for the argument list on the platform, allowing for the environment which comes out of the argument list length — so the length of the argument list plus the length of the environment has to be less than a maximum value.

IOW, find does the job right, like xargs does the job right. You should be able to build on BSD as well, though there aren't any provided binaries. You can invoke it with poly. John John But find. So I count the number of files instead don't I? Programmer yes, you'd need xargs , and you'd also need to watch for multiple wc invocations if you have lots of files; you'd need to look for all the total lines and sum them.

If you just want the total line count, you'd need to do find. Note that this find. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Stack Gives Back Safety in numbers: crowdsourcing data on nefarious IP addresses. Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually.

Linked Related 2. Hot Network Questions. EDIT: it turns out I was missing something after all. Take a look at orbitbot's comment for details. So I wrote a quick script to fetch the data and do the calculation:. Disclaimer thanks to lovasoa :. Looks like this method to calculate total line numbers isn't entirely reliable. That's the only way I know you're going to get lines of code. Another option is to use the API to list the languages the project uses.

It doesn't give them in lines but in bytes. For example Finally, you can use code search to ask which files match a given language. This example asks which files in perl5i are Perl. It will not give you lines, and you have to ask for the file size separately using the returned url for each file. I have talked to customer support and confirmed that this can not be done on github.

They have passed the suggestion along to the Github team though, so hopefully it will be possible in the future. If so, I'll be sure to edit this answer. Meanwhile, Rory O'Kane's answer is a brilliant alternative based on cloc and a shallow repo clone.

Personally I made an chrome extension which shows the number of SLOC on both github project list and project detail page. You can also set your personal access token to access private repositories and bypass the api rate limit.

By default the badge will show the repo's LoC Lines of Code , you can also specify for it to show a different category, by using the? It can be either code, blanks, files, lines, comments. I wrote a small firefox addon that prints the number of lines of code on github project pages: Github SLOC. Regular expressions can be used to exclude files and folders Further information on npm. Powershell: rm -r -force ". However, if the question is "can you quickly check the SCALE of a project", I usually gauge a project by looking at its size.

Of course the size will include deltas from all active commits, but it is a good metric as the order of magnitude is quite close. In your browser, enter api. This should give you an idea of the relative scale of the project. The number seems to be in KB, but when I checked it on my computer it's actually smaller, even though the order of magnitude is consistent.

And the added benefit is that if you don't approve the PR and just leave it in place, the stats No of commits, files changed and total lines of code will simply keep up-to-date as you merge changes into main.

Pipe the output from the number of lines in each file to sort to organize files by line count. This is so easy if you are using Vscode and you clone the project first. The extension shows summary statistics by file type and it also outputs result files with detailed information by each folder. None of the answers here satisfied my requirements. I only wanted to use existing utilities. The following script will use basic utilities:. Get lines of code filtered by specified file types of known source code e.

Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Can you get the number of lines of code from a GitHub repository? Ask Question. Asked 7 years, 2 months ago. Active 29 days ago. Viewed k times. Cloning a project like Wine, for example, takes ages. Luc 3, 2 2 gold badges 40 40 silver badges 43 43 bronze badges. Hubro Hubro 51k 61 61 gold badges silver badges bronze badges.

Schwern: Didn't really think about that. The latest commit of the master branch, I suppose. Abizern: Is that a valid reason for closing a question? I'm trying to find that in the guidelines. My plan was to ask on SO first. If that proved futile, I'd ask Github customer support and post their information as an answer here.

Abizern: See on-topic. It says you can ask questions about "software tools commonly used by programmers". Hubro 1 I've solved with git clone --depth 1. As for 2 and 3, I suspect there is software out there which can do the analysis for you, and you can do a lot of guessing based on file extensions, but I'm having a hell of a time coming up with a good search term to find said software.

Maybe you need to ask another question. Not so direct way to get line count. But you can use awk or sed to get the count from last line. For example:. You can also use vi and vim with the command ":set number" to set the number on each line as shown below. Use the cat command with -n switch to get each line numbered. Again, here you can get the line count from the last line.



0コメント

  • 1000 / 1000