mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +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
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
# linguist — detect language type for a file, or, given a directory, determine language breakdown
|
# 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/file_blob'
|
||||||
require 'linguist/repository'
|
require 'linguist/repository'
|
||||||
|
|
||||||
path = ARGV[0] || Dir.pwd
|
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)
|
if File.directory?(path)
|
||||||
repo = Linguist::Repository.from_directory(path)
|
repo = Linguist::Repository.from_directory(path)
|
||||||
repo.languages.sort_by { |_, size| size }.reverse.each do |language, size|
|
repo.languages.sort_by { |_, size| size }.reverse.each do |language, size|
|
||||||
@@ -15,10 +24,12 @@ if File.directory?(path)
|
|||||||
percentage = sprintf '%.2f' % percentage
|
percentage = sprintf '%.2f' % percentage
|
||||||
puts "%-7s %s" % ["#{percentage}%", language]
|
puts "%-7s %s" % ["#{percentage}%", language]
|
||||||
end
|
end
|
||||||
puts
|
if breakdown
|
||||||
breakdown = repo.breakdown_by_file
|
puts
|
||||||
breakdown.each do |lang, files|
|
breakdown = repo.breakdown_by_file
|
||||||
puts "#{lang}: #{files}"
|
breakdown.each do |lang, files|
|
||||||
|
puts "#{lang}: #{files}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
elsif File.file?(path)
|
elsif File.file?(path)
|
||||||
blob = Linguist::FileBlob.new(path, Dir.pwd)
|
blob = Linguist::FileBlob.new(path, Dir.pwd)
|
||||||
|
|||||||
Reference in New Issue
Block a user