From 9823af0cb45291c2ccf540dcf2567e4c142e41dd Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Thu, 20 Nov 2014 12:50:35 -0500 Subject: [PATCH] Fix for shebang with relative bin `#!/usr/bin/env bin/linguist` is a valid shebang --- lib/linguist/languages.yml | 2 ++ lib/linguist/samples.rb | 7 +++++-- test/test_samples.rb | 5 +++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 810f6685..db9ece79 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -544,6 +544,8 @@ Crystal: - .cr ace_mode: ruby tm_scope: source.ruby + interpreters: + - crystal Cucumber: extensions: diff --git a/lib/linguist/samples.rb b/lib/linguist/samples.rb index 2d72296a..001204b5 100644 --- a/lib/linguist/samples.rb +++ b/lib/linguist/samples.rb @@ -133,6 +133,9 @@ module Linguist script = script == 'env' ? tokens[1] : script + # If script has an invalid shebang, we might get here + return unless script + # "python2.6" -> "python2" script.sub! $1, '' if script =~ /(\.\d+)$/ @@ -141,8 +144,8 @@ module Linguist lines[0...5].any? { |l| l.match(/exec (\w+).+\$0.+\$@/) } script = $1 end - - script + + File.basename(script) else nil end diff --git a/test/test_samples.rb b/test/test_samples.rb index b36cf363..cf7a276b 100644 --- a/test/test_samples.rb +++ b/test/test_samples.rb @@ -85,4 +85,9 @@ class TestSamples < Test::Unit::TestCase end end end + + def test_shebang + assert_equal "crystal", Linguist.interpreter_from_shebang("#!/usr/bin/env bin/crystial") + assert_equal "python2", Linguist.interpreter_from_shebang("#!/usr/bin/python2.4") + end end