From 21b8e16afc15e84dce7161822aba173eba52750c Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Wed, 10 Dec 2014 12:05:37 -0500 Subject: [PATCH] Use #start_with? for clarity --- lib/linguist/shebang.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/linguist/shebang.rb b/lib/linguist/shebang.rb index 4e47ad6b..6f04e866 100644 --- a/lib/linguist/shebang.rb +++ b/lib/linguist/shebang.rb @@ -18,12 +18,13 @@ module Linguist # # Returns a String or nil def self.interpreter(data) - lines = data.lines + shebang = data.lines.first # First line must start with #! - return unless match = /^#!(.+)$/.match(lines.first) + return unless shebang && shebang.start_with?("#!") - tokens = match[1].strip.split(' ') + # Get the parts of the shebang without the #! + tokens = shebang.sub(/^#!\s*/, '').strip.split(' ') # There was nothing after the #! return if tokens.empty? @@ -42,7 +43,7 @@ module Linguist # Check for multiline shebang hacks that call `exec` if script == 'sh' && - lines.first(5).any? { |l| l.match(/exec (\w+).+\$0.+\$@/) } + data.lines.first(5).any? { |l| l.match(/exec (\w+).+\$0.+\$@/) } script = $1 end