{"id":24506185,"url":"https://github.com/pvdb/gloc","last_synced_at":"2025-04-14T07:08:50.456Z","repository":{"id":47794786,"uuid":"77630219","full_name":"pvdb/gloc","owner":"pvdb","description":"yet another code counter","archived":false,"fork":false,"pushed_at":"2022-07-21T09:41:28.000Z","size":30,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-19T03:42:54.531Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pvdb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-29T17:55:50.000Z","updated_at":"2022-07-22T08:45:11.000Z","dependencies_parsed_at":"2022-09-03T06:24:13.135Z","dependency_job_id":null,"html_url":"https://github.com/pvdb/gloc","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pvdb%2Fgloc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pvdb%2Fgloc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pvdb%2Fgloc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pvdb%2Fgloc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pvdb","download_url":"https://codeload.github.com/pvdb/gloc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235039161,"owners_count":18926297,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-21T23:33:26.794Z","updated_at":"2025-01-21T23:33:27.401Z","avatar_url":"https://github.com/pvdb.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# yet another code counter: `gloc`\n\n`gloc` is [yet another code counter](https://github.com/search?q=%22code+counter%22), with some differences and enhancements compared to similar utilities.\n\nMost importantly, it simply groups files based on their file extension, unlike other code counters that group files based on the - oftentimes incorrect - language of their content _(as determined by whatever \"language detection\" heuristics these tools may use)_.\n\nFurther differences and enhancements:\n\n* it doesn't ignore files just because it doesn't recognise them _(ie. cannot correctly determine or guess their language)_\n* in a git repo, it processes `$( git ls-files )` by default\n* in a non-git directory, it processes `$( find . -type f )` by default\n* it generates human-friendly, `(c)loc`-alike output\n* it is Unix pipeline friendly, by design:\n   * it reads the list of filenames to process from `stdin` if `[ ! -t 0 ]`\n   * it writes machine-parsable JSON output to `stdout` if `[ ! -t 1 ]`\n\n## Example\n\nFor the popular Ruby on Rails framework, `gloc` generates the following `(c)loc`-alike output:\n\n    --------------------------------------------------------------------------------\n     Language             Files        Lines        Blank      Comment         Code\n    --------------------------------------------------------------------------------\n     *.rb                 2,149      304,495       47,846       42,651      213,998\n     *.md                    74       49,604       14,204            0       35,400\n     *.js                    39        9,717        1,452          564        7,701\n     *.yml                  150        3,367          278            0        3,089\n     *.erb                  408        2,183          254            0        1,929\n     *                       81        2,255          392            0        1,863\n     *.css                   24        1,640          214           32        1,394\n     *.coffee                24        1,190          197            0          993\n     *.rake                  16          864          137            0          727\n     *.rdoc                  11          985          352            0          633\n     *.tt                    28          515           88            0          427\n     *.lock                   1          437           11            0          426\n     *.yaml                   1          231            1            0          230\n     *.gemspec               11          306           79            0          227\n     *.html                  28          225           15            3          207\n     *.json                   3           65            0            0           65\n     *.builder               19           62            2            0           60\n     *.y                      1           50            4            0           46\n     *.sql                    1           49            6            0           43\n     *.zoo                    2            8            0            0            8\n     *.ru                     2            8            2            0            6\n     *.txt                    6            6            0            0            6\n     *.ruby                   2            4            0            0            4\n     *.erb~                   4            4            0            0            4\n     *.raw                    2            2            0            0            2\n     *.styles                 1            1            0            0            1\n     *.log                    1            1            0            0            1\n     *.dtd                    1            1            0            0            1\n     *.mab                    1            1            0            0            1\n     *.javascript             1            1            0            0            1\n    --------------------------------------------------------------------------------\n     Total                3,092      378,277       65,534       43,250      269,493\n    --------------------------------------------------------------------------------\n\n## What It Is Not!\n\nFor various reasons, none of these existing utilities to count lines of code are fit for _(my)_ purpose:\n\n* [cgag/loc](https://github.com/cgag/loc)\n* [AlDanial/cloc](https://github.com/AlDanial/cloc)\n* [Aaronepower/tokei](https://github.com/Aaronepower/tokei)\n* [SLOCCount](http://www.dwheeler.com/sloccount/)\n\nAnd it **definitely** isn't:\n\n* [LocMetrics](http://www.locmetrics.com/)\n\n## Installation\n\n    gem install gloc\n\n## Usage\n\nThe simplest way to use `gloc` is to simply run:\n\n    gloc\n\nIt should behave pretty much as you'd expect!\n\n### in a git repo\n\nIn a git repo, running `gloc` will process all files known to git, so is roughly equivalent to:\n\n    git ls-files | gloc\n\n### in a non-git repo\n\nIn a non-git repo, running `gloc` will process all files in the directory, so is roughly equivalent to:\n\n    find . -type f | gloc\n\n## Sorting\n\nThe results are sorted by \"lines of code\" by default _(with \"lines of code\" defined as lines that aren't blank or comment-only)_ but the following options are supported to sort the results differently:\n\n    gloc -files     # sort by number of files\n    gloc -lines     # sort by the total number of lines\n    gloc -blank     # sort by the number of blank lines\n    gloc -comment   # sort by the number of comment lines\n    gloc -code      # sort by lines of code (default)\n\n## Processing\n\nWhen `gloc`'s STDOUT isn't a TTY, it outputs the LoC stats in JSON format, for further parsing and processing.\n\nThis also means you can pretty-print the LoC stats as follows:\n\n    gloc | jq\n\n... which uses the [the `jq` utility](https://stedolan.github.io/jq/) for processing the JSON output.\n\nTo \"force\" the typical TTY output even when STDOUT isn't a TTY, you can use the `-tty` option as follows:\n\n    gloc -tty | pbcopy\n\n... which copies the non-JSON version of the LoC stats to the clipboard.\n\n## Known Issues and Possible Enhancements\n\n* identify comment-only lines for a lot more languages\n* support more file encodings (not just `UTF-8` and `ISO-8859-1`)\n* (?) parse shebang lines for scripts without a file extension\n* (?) installation via Homebrew\n* (?) convert script to Perl for performance\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/pvdb/gloc. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpvdb%2Fgloc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpvdb%2Fgloc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpvdb%2Fgloc/lists"}