mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 09:40:21 +00:00
Add --breakdown option for linguist binary
This commit is contained in:
21
bin/linguist
21
bin/linguist
@@ -1,13 +1,22 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# linguist — detect language type for a file, or, given a directory, determine language breakdown
|
||||
# usage: linguist <path>
|
||||
# usage: linguist <path> [<--breakdown>]
|
||||
|
||||
require 'linguist/file_blob'
|
||||
require 'linguist/repository'
|
||||
|
||||
path = ARGV[0] || Dir.pwd
|
||||
|
||||
# special case if not given a directory but still given the --breakdown option
|
||||
if path == "--breakdown"
|
||||
path = Dir.pwd
|
||||
breakdown = true
|
||||
end
|
||||
|
||||
ARGV.shift
|
||||
breakdown = true if ARGV[0] == "--breakdown"
|
||||
|
||||
if File.directory?(path)
|
||||
repo = Linguist::Repository.from_directory(path)
|
||||
repo.languages.sort_by { |_, size| size }.reverse.each do |language, size|
|
||||
@@ -15,10 +24,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}"
|
||||
if breakdown
|
||||
puts
|
||||
breakdown = repo.breakdown_by_file
|
||||
breakdown.each do |lang, files|
|
||||
puts "#{lang}: #{files}"
|
||||
end
|
||||
end
|
||||
elsif File.file?(path)
|
||||
blob = Linguist::FileBlob.new(path, Dir.pwd)
|
||||
|
||||
Reference in New Issue
Block a user