Used to retrieve the interpreter from the shebang line of a file’s data.
# File lib/linguist/samples.rb, line 116 def self.interpreter_from_shebang(data) lines = data.lines.to_a if lines.any? && (match = lines[0].match(/(.+)\n?/)) && (bang = match[0]) =~ /^#!/ bang.sub!(/^#! /, '#!') tokens = bang.split(' ') pieces = tokens.first.split('/') if pieces.size > 1 script = pieces.last else script = pieces.first.sub('#!', '') end script = script == 'env' ? tokens[1] : script # "python2.6" -> "python" if script =~ /((?:\d+\.?)+)/ script.sub! $1, '' end # Check for multiline shebang hacks that call `exec` if script == 'sh' && lines[0...5].any? { |l| l.match(/exec (\w+).+\$0.+\$@/) } script = $1 end script else nil end end
Generated with the Darkfish Rdoc Generator 2.