diff --git a/bin/linguist b/bin/linguist index 3bbe1e13..54ee8234 100755 --- a/bin/linguist +++ b/bin/linguist @@ -15,6 +15,12 @@ if File.directory?(path) percentage = sprintf '%.2f' % percentage puts "%-7s %s" % ["#{percentage}%", language] end + puts + breakdown = repo.breakdown_by_file + breakdown.each do |lang, files| + puts "#{lang}: #{files}" + puts + end elsif File.file?(path) blob = Linguist::FileBlob.new(path, Dir.pwd) type = if blob.text? diff --git a/lib/linguist/repository.rb b/lib/linguist/repository.rb index 4b34be0a..b91d2401 100644 --- a/lib/linguist/repository.rb +++ b/lib/linguist/repository.rb @@ -29,6 +29,7 @@ module Linguist @computed_stats = false @language = @size = nil @sizes = Hash.new { 0 } + @file_breakdown = {} end # Public: Returns a breakdown of language stats. @@ -60,6 +61,12 @@ module Linguist @size end + # Public: Return the language breakdown of this repository by file + def breakdown_by_file + compute_stats unless @computed_stats + @file_breakdown + end + # Internal: Compute language breakdown for each blob in the Repository. # # Returns nothing @@ -75,6 +82,14 @@ module Linguist # Only include programming languages and acceptable markup languages if blob.language.type == :programming || Language.detectable_markup.include?(blob.language.name) + + # Build up the per-file breakdown stats if asked + if @file_breakdown[blob.language.group.name] + @file_breakdown[blob.language.group.name] << blob.name + else + @file_breakdown[blob.language.group.name] = [blob.name] + end + @sizes[blob.language.group] += blob.size end end