mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-12-28 21:01:00 +00:00
document shebang code
This commit is contained in:
@@ -20,18 +20,25 @@ module Linguist
|
|||||||
def self.interpreter(data)
|
def self.interpreter(data)
|
||||||
lines = data.lines
|
lines = data.lines
|
||||||
|
|
||||||
|
# First line must start with #!
|
||||||
return unless match = /^#!(.+)$/.match(lines.first)
|
return unless match = /^#!(.+)$/.match(lines.first)
|
||||||
|
|
||||||
tokens = match[1].strip.split(' ')
|
tokens = match[1].strip.split(' ')
|
||||||
|
|
||||||
|
# There was nothing after the #!
|
||||||
return if tokens.empty?
|
return if tokens.empty?
|
||||||
|
|
||||||
|
# Get the name of the interpreter
|
||||||
script = File.basename(tokens.first)
|
script = File.basename(tokens.first)
|
||||||
|
|
||||||
|
# Get next argument if interpreter was /usr/bin/env
|
||||||
script = tokens[1] if script == 'env'
|
script = tokens[1] if script == 'env'
|
||||||
|
|
||||||
# If script has an invalid shebang, we might get here
|
# Interpreter was /usr/bin/env with no arguments
|
||||||
return unless script
|
return unless script
|
||||||
|
|
||||||
# "python2.6" -> "python2"
|
# "python2.6" -> "python2"
|
||||||
script.sub! $1, '' if script =~ /(\.\d+)$/
|
script.sub! /(\.\d+)$/, ''
|
||||||
|
|
||||||
# Check for multiline shebang hacks that call `exec`
|
# Check for multiline shebang hacks that call `exec`
|
||||||
if script == 'sh' &&
|
if script == 'sh' &&
|
||||||
|
|||||||
Reference in New Issue
Block a user