Language Savant. If your repository's language is being reported incorrectly, send us a pull request!
Перейти к файлу
davidhq cbb23aef82
Add Yul smart contract language (#5861)
* Add Yul smart contract langauge (intermediate language for Ethereum Virtual Machine)

* add yul to grammars.yml

* remove yulp extension

Co-authored-by: Colin Seymour <colin@github.com>
2022-04-26 10:27:59 +01:00
.github Fix docker test (#5873) 2022-04-26 09:33:30 +01:00
bin Declare program version for `OptionParser` (#5766) 2022-02-09 18:01:09 +00:00
docs Remove references to Lightshow (#5845) 2022-03-30 11:29:21 +01:00
ext/linguist Truncate long tokens (#5205) 2021-02-11 09:42:41 +00:00
lib Add Yul smart contract language (#5861) 2022-04-26 10:27:59 +01:00
samples Add Yul smart contract language (#5861) 2022-04-26 10:27:59 +01:00
script Elixir and PHP now use Treesitter grammars (#5797) 2022-02-21 09:58:37 +00:00
test Register `.url` as a generic INI extension (#5837) 2022-03-28 10:15:01 +01:00
tools/grammars Release v7.19.0 (#5798) 2022-02-21 13:54:18 +00:00
vendor Add Yul smart contract language (#5861) 2022-04-26 10:27:59 +01:00
.dockerignore Add Dockerfile (#4687) 2020-09-08 09:54:02 +01:00
.editorconfig Rewrite `script/add-grammar` as a plain shell-script (#5521) 2021-09-02 21:14:21 +10:00
.gitignore Release 7.18.0 (#5686) 2021-12-15 14:01:24 +00:00
.gitmodules Replace Cobol grammar (#5846) 2022-04-01 10:49:42 +01:00
CONTRIBUTING.md Remove references to Lightshow (#5845) 2022-03-30 11:29:21 +01:00
Dockerfile Use OpenSSL instead of LibreSSL in Dockerfile (#5560) 2021-09-08 12:00:52 +01:00
Gemfile Byebug requires Ruby 2.2 (#3790) 2017-08-24 10:17:12 +01:00
LICENSE Update LICENSE 2017-02-15 14:11:37 -08:00
README.md Add filesize metrics to `github-linguist` output (#5464) 2021-07-19 16:32:54 +01:00
Rakefile Release v7.17.0 (#5604) 2021-10-19 15:23:15 +01:00
github-linguist.gemspec Exclude compiled extension from gem (#5818) 2022-03-04 14:44:28 +00:00
grammars.yml Add Yul smart contract language (#5861) 2022-04-26 10:27:59 +01:00

README.md

Linguist

Actions Status

This 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.

Documentation

Installation

Install the gem:

gem install github-linguist

Dependencies

Linguist is a Ruby library so you will need a recent version of Ruby installed. There are known problems with the macOS/XCode supplied version of Ruby that causes problems installing some of the dependencies. Accordingly, 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.

Linguist uses charlock_holmes for character encoding and rugged for libgit2 bindings for Ruby. These components have their own dependencies.

  1. charlock_holmes
  2. rugged

You may need to install missing dependencies before you can install Linguist. For example, on macOS with Homebrew:

brew install cmake pkg-config icu4c

On Ubuntu:

sudo apt-get install cmake pkg-config libicu-dev zlib1g-dev libcurl4-openssl-dev libssl-dev ruby-dev

Usage

Application usage

Linguist can be used in your application as follows:

require 'rugged'
require 'linguist'

repo = Rugged::Repository.new('.')
project = Linguist::Repository.new(repo, repo.head.target_id)
project.language       #=> "Ruby"
project.languages      #=> { "Ruby" => 119387 }

Command line usage

Git Repository

A repository's languages stats can also be assessed from the command line using the github-linguist executable. Without any options, github-linguist will output the language breakdown by percentage and file size.

cd /path-to-repository
github-linguist

You can try running github-linguist on the root directory in this repository itself:

$ github-linguist
66.84%  264519     Ruby
24.68%  97685      C
6.57%   25999      Go
1.29%   5098       Lex
0.32%   1257       Shell
0.31%   1212       Dockerfile

Additional options

--breakdown

The --breakdown or -b flag will additionally show the breakdown of files by language.

You can try running github-linguist on the root directory in this repository itself:

$ github-linguist --breakdown
66.84%  264519     Ruby
24.68%  97685      C
6.57%   25999      Go
1.29%   5098       Lex
0.32%   1257       Shell
0.31%   1212       Dockerfile

Ruby:
Gemfile
Rakefile
bin/git-linguist
bin/github-linguist
ext/linguist/extconf.rb
github-linguist.gemspec
lib/linguist.rb
--json

The --json or -j flag output the data into JSON format.

$ github-linguist --json
{"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"}}

This option can be used in conjunction with --breakdown to get a full list of files along with the size and percentage data.

$ github-linguist --breakdown --json
{"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",...]}}

Single file

Alternatively you can find stats for a single file using the github-linguist executable.

You can try running github-linguist on files in this repository itself:

$ github-linguist grammars.yml
grammars.yml: 884 lines (884 sloc)
  type:      Text
  mime type: text/x-yaml
  language:  YAML

Docker

If you have Docker installed you can build an image and run Linguist within a container:

$ docker build -t linguist .
$ docker run --rm -v $(pwd):$(pwd) -w $(pwd) -t linguist
66.84%  264519     Ruby
24.68%  97685      C
6.57%   25999      Go
1.29%   5098       Lex
0.32%   1257       Shell
0.31%   1212       Dockerfile
$ docker run --rm -v $(pwd):$(pwd) -w $(pwd) -t linguist github-linguist --breakdown
66.84%  264519     Ruby
24.68%  97685      C
6.57%   25999      Go
1.29%   5098       Lex
0.32%   1257       Shell
0.31%   1212       Dockerfile

Ruby:
Gemfile
Rakefile
bin/git-linguist
bin/github-linguist
ext/linguist/extconf.rb
github-linguist.gemspec
lib/linguist.rb

Contributing

Please check out our contributing guidelines.

License

The language grammars included in this gem are covered by their repositories' respective licenses. vendor/README.md lists the repository for each grammar.

All other files are covered by the MIT license, see LICENSE.