mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
@@ -308,7 +308,7 @@ module Linguist
|
||||
# Fail fast if blob isn't viewable?
|
||||
return unless viewable?
|
||||
|
||||
if data && (match = data.match(/(.+)\n?/)) && (bang = match[0]) =~ /^#!/
|
||||
if data && (match = lines[0].match(/(.+)\n?/)) && (bang = match[0]) =~ /^#!/
|
||||
bang.sub!(/^#! /, '#!')
|
||||
tokens = bang.split(' ')
|
||||
pieces = tokens.first.split('/')
|
||||
@@ -325,6 +325,16 @@ module Linguist
|
||||
script.sub! $1, ''
|
||||
end
|
||||
|
||||
# Check for multiline shebang hacks that exec themselves
|
||||
#
|
||||
# #!/bin/sh
|
||||
# exec foo "$0" "$@"
|
||||
#
|
||||
if script == 'sh' &&
|
||||
lines[0...5].any? { |l| l.match(/exec (\w+).+\$0.+\$@/) }
|
||||
script = $1
|
||||
end
|
||||
|
||||
script
|
||||
end
|
||||
end
|
||||
|
||||
7
test/fixtures/script.rkt
vendored
Normal file
7
test/fixtures/script.rkt
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
#| -*- scheme -*-
|
||||
exec racket -um "$0" "$@"
|
||||
|#
|
||||
|
||||
(require racket/file racket/path racket/list racket/string
|
||||
(for-syntax racket/base))
|
||||
9
test/fixtures/script.scala
vendored
Normal file
9
test/fixtures/script.scala
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
exec scala "$0" "$@"
|
||||
!#
|
||||
|
||||
object HelloWorld {
|
||||
def main(args: Array[String]) {
|
||||
println("Hello, world!")
|
||||
}
|
||||
}
|
||||
@@ -286,6 +286,8 @@ class TestBlob < Test::Unit::TestCase
|
||||
assert_equal 'rake', blob("script.rake").shebang_script
|
||||
assert_equal 'foo', blob("script.foo").shebang_script
|
||||
assert_equal 'nush', blob("script.nu").shebang_script
|
||||
assert_equal 'scala', blob("script.scala").shebang_script
|
||||
assert_equal 'racket', blob("script.rkt").shebang_script
|
||||
assert_equal nil, blob("foo.rb").shebang_script
|
||||
end
|
||||
|
||||
@@ -301,6 +303,8 @@ class TestBlob < Test::Unit::TestCase
|
||||
assert_equal Language['Ruby'], blob("script.mrb").shebang_language
|
||||
assert_equal Language['Ruby'], blob("script.rake").shebang_language
|
||||
assert_equal Language['Nu'], blob("script.nu").shebang_language
|
||||
assert_equal Language['Scala'], blob("script.scala").shebang_language
|
||||
assert_equal Language['Racket'], blob("script.rkt").shebang_language
|
||||
assert_equal nil, blob("script.foo").shebang_language
|
||||
assert_equal nil, blob("foo.rb").shebang_language
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user