Merge pull request #1604 from geoff-codes/#!--"

Comment styles; don't choke on `#!/usr/bin/env foo=bar`
This commit is contained in:
Arfon Smith
2015-04-01 15:18:40 -05:00
6 changed files with 1520 additions and 0 deletions

View File

@@ -2930,6 +2930,7 @@ Shell:
- .fcgi
- .ksh
- .tmux
- .tool
- .zsh
interpreters:
- bash

View File

@@ -22,8 +22,10 @@ module Linguist
# Start state on token, ignore anything till the next newline
SINGLE_LINE_COMMENTS = [
'//', # C
'--', # Ada, Haskell, AppleScript
'#', # Ruby
'%', # Tex
'"', # Vim
]
# Start state on opening token, ignore anything until the closing
@@ -130,6 +132,9 @@ module Linguist
# extract_shebang("#!/usr/bin/env node")
# # => "node"
#
# extract_shebang("#!/usr/bin/env A=B foo=bar awk -f")
# # => "awk"
#
# Returns String token or nil it couldn't be parsed.
def extract_shebang(data)
s = StringScanner.new(data)
@@ -138,6 +143,7 @@ module Linguist
script = path.split('/').last
if script == 'env'
s.scan(/\s+/)
s.scan(/.*=[^\s]+\s+/)
script = s.scan(/\S+/)
end
script = script[/[^\d]+/, 0] if script