{"id":13474080,"url":"https://github.com/github-linguist/linguist","last_synced_at":"2025-05-12T17:48:13.033Z","repository":{"id":1480020,"uuid":"1725199","full_name":"github-linguist/linguist","owner":"github-linguist","description":"Language Savant. If your repository's language is being reported incorrectly, send us a pull request!","archived":false,"fork":false,"pushed_at":"2025-04-25T14:29:54.000Z","size":40775,"stargazers_count":12676,"open_issues_count":222,"forks_count":4480,"subscribers_count":536,"default_branch":"main","last_synced_at":"2025-04-25T14:50:17.864Z","etag":null,"topics":["language-grammars","language-statistics","linguistic","syntax-highlighting"],"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/github-linguist.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2011-05-09T22:53:13.000Z","updated_at":"2025-04-25T14:47:58.000Z","dependencies_parsed_at":"2023-07-06T16:16:17.984Z","dependency_job_id":"f433e58a-19fe-4f4b-ae67-f82b5ecaa8dc","html_url":"https://github.com/github-linguist/linguist","commit_stats":{"total_commits":5016,"total_committers":1172,"mean_commits":4.279863481228669,"dds":0.8789872408293461,"last_synced_commit":"7ca3799b8b5f1acde1dd7a8dfb7ae849d3dfb4cd"},"previous_names":["github/linguist"],"tags_count":181,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github-linguist%2Flinguist","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github-linguist%2Flinguist/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github-linguist%2Flinguist/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github-linguist%2Flinguist/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/github-linguist","download_url":"https://codeload.github.com/github-linguist/linguist/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251207130,"owners_count":21552515,"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":["language-grammars","language-statistics","linguistic","syntax-highlighting"],"created_at":"2024-07-31T16:01:09.398Z","updated_at":"2025-04-27T20:43:30.792Z","avatar_url":"https://github.com/github-linguist.png","language":"Ruby","funding_links":[],"categories":["Ruby","CLI","others","其他","Project Quality","Uncategorized"],"sub_categories":["网络服务_其他","Uncategorized"],"readme":"# Linguist\n\n[![Actions Status](https://github.com/github/linguist/workflows/Run%20Tests/badge.svg)](https://github.com/github/linguist/actions) \n\n[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/github-linguist/linguist)\n\nThis library is used on GitHub.com to detect blob languages, ignore binary or vendored files, suppress generated files in diffs, and generate language breakdown graphs.\n\n## Documentation\n\n- [How Linguist works](/docs/how-linguist-works.md)\n- [Change Linguist's behaviour with overrides](/docs/overrides.md)\n- [Troubleshooting](/docs/troubleshooting.md)\n- [Contributing guidelines](CONTRIBUTING.md)\n\n## Installation\n\nInstall the gem:\n\n```bash\ngem install github-linguist\n```\n\n### Dependencies\n\nLinguist is a Ruby library so you will need a recent version of Ruby installed.\nThere are known problems with the macOS/Xcode supplied version of Ruby that causes problems installing some of the dependencies.\nAccordingly, we highly recommend you install a version of Ruby using Homebrew, `rbenv`, `rvm`, `ruby-build`, `asdf` or other packaging system, before attempting to install Linguist and the dependencies.\n\nLinguist uses [`charlock_holmes`](https://github.com/brianmario/charlock_holmes) for character encoding and [`rugged`](https://github.com/libgit2/rugged) for libgit2 bindings for Ruby.\nThese components have their own dependencies.\n\n1. charlock_holmes\n    * cmake\n    * pkg-config\n    * [ICU](http://site.icu-project.org/)\n    * [zlib](https://zlib.net/)\n2. rugged\n    * [libcurl](https://curl.haxx.se/libcurl/)\n    * [OpenSSL](https://www.openssl.org)\n\nYou may need to install missing dependencies before you can install Linguist.\nFor example, on macOS with [Homebrew](http://brew.sh/):\n\n```bash\nbrew install cmake pkg-config icu4c\n```\n\nOn Ubuntu:\n\n```bash\nsudo apt-get install build-essential cmake pkg-config libicu-dev zlib1g-dev libcurl4-openssl-dev libssl-dev ruby-dev\n```\n\n## Usage\n\n### Application usage\n\nLinguist can be used in your application as follows:\n\n```ruby\nrequire 'rugged'\nrequire 'linguist'\n\nrepo = Rugged::Repository.new('.')\nproject = Linguist::Repository.new(repo, repo.head.target_id)\nproject.language       #=\u003e \"Ruby\"\nproject.languages      #=\u003e { \"Ruby\" =\u003e 119387 }\n```\n\n### Command line usage\n\n#### Git Repository\n\nA repository's languages stats can also be assessed from the command line using the `github-linguist` executable.\nWithout any options, `github-linguist` will output the language breakdown by percentage and file size.\n\n```bash\ncd /path-to-repository\ngithub-linguist\n```\n\nYou can try running `github-linguist` on the root directory in this repository itself:\n\n```console\n$ github-linguist\n66.84%  264519     Ruby\n24.68%  97685      C\n6.57%   25999      Go\n1.29%   5098       Lex\n0.32%   1257       Shell\n0.31%   1212       Dockerfile\n```\n\n#### Additional options\n\n##### `--rev REV`\n\nThe `--rev REV` flag will change the git revision being analyzed to any [gitrevisions(1)](https://git-scm.com/docs/gitrevisions#_specifying_revisions) compatible revision you specify.\n\nThis is useful to analyze the makeup of a repo as of a certain tag, or in a certain branch.\n\nFor example, here is the popular [Jekyll open source project](https://github.com/jekyll/jekyll).\n\n```console\n$ github-linguist jekyll\n\n70.64%  709959     Ruby\n23.04%  231555     Gherkin\n3.80%   38178      JavaScript\n1.19%   11943      HTML\n0.79%   7900       Shell\n0.23%   2279       Dockerfile\n0.13%   1344       Earthly\n0.10%   1019       CSS\n0.06%   606        SCSS\n0.02%   234        CoffeeScript\n0.01%   90         Hack\n```\n\nAnd here is Jekyll's published website, from the gh-pages branch inside their repository.\n\n```console\n$ github-linguist jekyll --rev origin/gh-pages\n100.00% 2568354    HTML\n```\n\n##### `--breakdown`\n\nThe `--breakdown` or `-b` flag will additionally show the breakdown of files by language.\n\nYou can try running `github-linguist` on the root directory in this repository itself:\n\n```console\n$ github-linguist --breakdown\n66.84%  264519     Ruby\n24.68%  97685      C\n6.57%   25999      Go\n1.29%   5098       Lex\n0.32%   1257       Shell\n0.31%   1212       Dockerfile\n\nRuby:\nGemfile\nRakefile\nbin/git-linguist\nbin/github-linguist\next/linguist/extconf.rb\ngithub-linguist.gemspec\nlib/linguist.rb\n…\n```\n\n##### `--json`\n\nThe `--json` or `-j` flag output the data into JSON format.\n\n```console\n$ github-linguist --json\n{\"Dockerfile\":{\"size\":1212,\"percentage\":\"0.31\"},\"Ruby\":{\"size\":264519,\"percentage\":\"66.84\"},\"C\":{\"size\":97685,\"percentage\":\"24.68\"},\"Lex\":{\"size\":5098,\"percentage\":\"1.29\"},\"Shell\":{\"size\":1257,\"percentage\":\"0.32\"},\"Go\":{\"size\":25999,\"percentage\":\"6.57\"}}\n```\n\nThis option can be used in conjunction with `--breakdown` to get a full list of files along with the size and percentage data.\n\n```console\n$ github-linguist --breakdown --json\n{\"Dockerfile\":{\"size\":1212,\"percentage\":\"0.31\",\"files\":[\"Dockerfile\",\"tools/grammars/Dockerfile\"]},\"Ruby\":{\"size\":264519,\"percentage\":\"66.84\",\"files\":[\"Gemfile\",\"Rakefile\",\"bin/git-linguist\",\"bin/github-linguist\",\"ext/linguist/extconf.rb\",\"github-linguist.gemspec\",\"lib/linguist.rb\",...]}}\n\n```\n\n#### Single file\n\nAlternatively you can find stats for a single file using the `github-linguist` executable.\n\nYou can try running `github-linguist` on files in this repository itself:\n\n```console\n$ github-linguist grammars.yml\ngrammars.yml: 884 lines (884 sloc)\n  type:      Text\n  mime type: text/x-yaml\n  language:  YAML\n```\n\n#### Docker\n\nIf you have Docker installed you can build an image and run Linguist within a container:\n\n```console\n$ docker build -t linguist .\n$ docker run --rm -v $(pwd):$(pwd):Z -w $(pwd) -t linguist\n66.84%  264519     Ruby\n24.68%  97685      C\n6.57%   25999      Go\n1.29%   5098       Lex\n0.32%   1257       Shell\n0.31%   1212       Dockerfile\n$ docker run --rm -v $(pwd):$(pwd) -w $(pwd) -t linguist github-linguist --breakdown\n66.84%  264519     Ruby\n24.68%  97685      C\n6.57%   25999      Go\n1.29%   5098       Lex\n0.32%   1257       Shell\n0.31%   1212       Dockerfile\n\nRuby:\nGemfile\nRakefile\nbin/git-linguist\nbin/github-linguist\next/linguist/extconf.rb\ngithub-linguist.gemspec\nlib/linguist.rb\n…\n```\n\n## Contributing\n\nPlease check out our [contributing guidelines](CONTRIBUTING.md).\n\n## License\n\nThe language grammars included in this gem are covered by their repositories' respective licenses.\n[`vendor/README.md`](/vendor/README.md) lists the repository for each grammar.\n\nAll other files are covered by the MIT license, see [`LICENSE`](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgithub-linguist%2Flinguist","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgithub-linguist%2Flinguist","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgithub-linguist%2Flinguist/lists"}