mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Add file inspection to bin
This commit is contained in:
32
bin/linguist
32
bin/linguist
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
require 'linguist/blob'
|
require 'linguist/file_blob'
|
||||||
require 'linguist/repository'
|
require 'linguist/repository'
|
||||||
|
|
||||||
path = ARGV[0] || Dir.pwd
|
path = ARGV[0] || Dir.pwd
|
||||||
@@ -11,6 +11,36 @@ if File.directory?(path)
|
|||||||
percentage = ((size / repo.size.to_f) * 100).round
|
percentage = ((size / repo.size.to_f) * 100).round
|
||||||
puts "%-4s %s" % ["#{percentage}%", language]
|
puts "%-4s %s" % ["#{percentage}%", language]
|
||||||
end
|
end
|
||||||
|
elsif File.file?(path)
|
||||||
|
blob = Linguist::FileBlob.new(path, Dir.pwd)
|
||||||
|
type = if blob.text?
|
||||||
|
'Text'
|
||||||
|
elsif blob.image?
|
||||||
|
'Image'
|
||||||
|
elsif blob.binary?
|
||||||
|
'Binary'
|
||||||
|
else
|
||||||
|
'???'
|
||||||
|
end
|
||||||
|
|
||||||
|
puts "#{blob.name}: #{blob.loc} lines (#{blob.sloc} sloc)"
|
||||||
|
puts " type: #{type}"
|
||||||
|
puts " extension: #{blob.pathname.extname}"
|
||||||
|
puts " mime type: #{blob.mime_type}"
|
||||||
|
puts " content type: #{blob.content_type}"
|
||||||
|
puts " language: #{blob.language}"
|
||||||
|
|
||||||
|
if blob.large?
|
||||||
|
puts " large (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
|
else
|
||||||
abort "usage: linguist <path>"
|
abort "usage: linguist <path>"
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user