Files
linguist/bin/linguist
Andy Grunwald fdf000ec62 Add decimal places to statistic output
If you analyze a project sometimes the statistic outputs a
language with 0%. At first it seems that the language is not
part of this project, but there are only some decimal places
missing.
2013-10-02 20:40:12 +02:00

48 lines
1.1 KiB
Ruby
Executable File

#!/usr/bin/env ruby
# linguist — detect language type for a file, or, given a directory, determine language breakdown
#
# usage: linguist <path>
require 'linguist/file_blob'
require 'linguist/repository'
path = ARGV[0] || Dir.pwd
if File.directory?(path)
repo = Linguist::Repository.from_directory(path)
repo.languages.sort_by { |_, size| size }.reverse.each do |language, size|
percentage = ((size / repo.size.to_f) * 100)
percentage = sprintf '%.2f' % percentage
puts "%-7s %s" % ["#{percentage}%", language]
end
elsif File.file?(path)
blob = Linguist::FileBlob.new(path, Dir.pwd)
type = if blob.text?
'Text'
elsif blob.image?
'Image'
else
'Binary'
end
puts "#{blob.name}: #{blob.loc} lines (#{blob.sloc} sloc)"
puts " type: #{type}"
puts " mime type: #{blob.mime_type}"
puts " language: #{blob.language}"
if blob.large?
puts " blob is too large to be shown"
end
if blob.generated?
puts " appears to be generated source code"
end
if blob.vendored?
puts " appears to be a vendored file"
end
else
abort "usage: linguist <path>"
end