mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
avoid load_blob and shebang check on files with extensions
previously, any file with an unrecognized file extension was loaded to check for a shebang. now, this only occurs if the file has a generic name with no file extension (like ./script) it is possible this will no longer match certain scripts with esoteric extensions (if we find these we can add them to the shebang_extname? method). however, most common script extensions (.sh, .rb, .pl, etc) will continue to work since the file extension takes precedence over the shebang line.
This commit is contained in:
@@ -142,6 +142,13 @@ module Linguist
|
||||
['.module', '.install', '.test', '.inc'].include?(extname)
|
||||
end
|
||||
|
||||
# Public: Is the blob likely to have a shebang?
|
||||
#
|
||||
# Return true or false
|
||||
def shebang_extname?
|
||||
extname.empty?
|
||||
end
|
||||
|
||||
MEGABYTE = 1024 * 1024
|
||||
|
||||
# Public: Is the blob too big to load?
|
||||
@@ -592,6 +599,9 @@ module Linguist
|
||||
#
|
||||
# Returns the Language or nil
|
||||
def shebang_language
|
||||
# Skip file extensions unlikely to have shebangs
|
||||
return unless shebang_extname?
|
||||
|
||||
if script = shebang_script
|
||||
Language[script]
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user