We use this library on GitHub to detect file language types for syntax highlighting, ignore binary files, suppress generated code in diffs and generate language breakdown graphs.
- Common extensions
- Shebang
- C header files (C/C++/Obj-C)
- Generated JS files (minified js, compiled CoffeeScript)
- Generated config files (Xcode project files and nibs)
- Ignores common vendored libs conventions (deps/, vendor/, jquery, prototype)
- Generates project LOC stats
file = Linguist::SourceFile.new("linguist.rb")
file.language.name #=> "Ruby"
file = Linguist::SourceFile.new("linguist.gem")
file.binary? #=> true
project = Linguist::Project.new(".")
project.language.name #=> "Ruby"
project.language_stats #=> { "Ruby" => 0.98, "Shell" => 0.02 }
# Using Grit backend
repo = Grit::Repo.new("./.git")
project = Linguist::Project.new(repo)
Once you've made your great commits:
- Fork it.
- Create a branch (
git checkout -b detect-foo-language
) - Commit your changes (
git commit -am "Added detection for the new Foo language"
) - Push to the branch (
git push origin detect-foo-language
) - Create a Pull Request from your branch.
- Promote it. Mention a public repository to demostration the value of your changes. Get others to drop in and 👍 it.