Add comment styles, don't choke on #!/usr/bin/env foo=bar...

This commit is contained in:
Geoff Nixon
2014-10-17 04:42:51 -07:00
parent e8cf750e18
commit edadca9085
6 changed files with 1520 additions and 0 deletions

View File

@@ -2309,6 +2309,7 @@ Shell:
- .command
- .fcgi
- .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
@@ -129,6 +131,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)
@@ -137,6 +142,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