Sha256: 80e3703c4b4c04c88adc95aee2b77891a4c5e84f376f175afd3a3d94fdbb222f

Contents?: true

Size: 1.52 KB

Versions: 13

Compression:

Stored size: 1.52 KB

Contents

#!/usr/bin/env ruby

# linguist — detect language type for a file, or, given a directory, determine language breakdown
#     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|
    percentage = ((size / repo.size.to_f) * 100)
    percentage = sprintf '%.2f' % percentage
    puts "%-7s %s" % ["#{percentage}%", language]
  end
  if breakdown
    puts
    file_breakdown = repo.breakdown_by_file
    file_breakdown.each do |lang, files|
      puts "#{lang}:" 
      files.each do |file|
        puts file
      end
      puts
    end
  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

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
github-linguist-2.12.1 bin/linguist
github-linguist-2.12.0 bin/linguist
github-linguist-2.11.5 bin/linguist
github-linguist-2.11.4 bin/linguist
github-linguist-2.11.3 bin/linguist
github-linguist-2.11.2 bin/linguist
github-linguist-2.11.1 bin/linguist
github-linguist-2.11.0 bin/linguist
github-linguist-2.10.15 bin/linguist
github-linguist-2.10.14 bin/linguist
github-linguist-2.10.13 bin/linguist
github-linguist-2.10.11 bin/linguist
github-linguist-2.10.10 bin/linguist