Module: Linguist
- Defined in:
- lib/linguist/md5.rb,
lib/linguist/samples.rb,
lib/linguist/language.rb,
lib/linguist/file_blob.rb,
lib/linguist/generated.rb,
lib/linguist/tokenizer.rb,
lib/linguist/classifier.rb,
lib/linguist/heuristics.rb,
lib/linguist/repository.rb,
lib/linguist/blob_helper.rb
Defined Under Namespace
Modules: BlobHelper, MD5, Samples Classes: Classifier, FileBlob, Generated, Heuristics, Language, Repository, Tokenizer
Class Method Summary collapse
-
.interpreter_from_shebang(data) ⇒ Object
Used to retrieve the interpreter from the shebang line of a file’s data.
Class Method Details
.interpreter_from_shebang(data) ⇒ Object
Used to retrieve the interpreter from the shebang line of a file’s data.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# 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 |