diff --git a/bin/linguist b/bin/linguist index 18ea3431..17008fe0 100755 --- a/bin/linguist +++ b/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 +# usage: linguist [<--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)