github-linguist 2.10.0 → 2.10.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -57,6 +57,7 @@ module Linguist
57
57
  yield({
58
58
  :path => File.join(dirname, filename),
59
59
  :language => category,
60
+ :interpreter => File.exist?(filename) ? Linguist.interpreter_from_shebang(File.read(filename)) : nil,
60
61
  :extname => File.extname(filename)
61
62
  })
62
63
  end
@@ -72,6 +73,7 @@ module Linguist
72
73
  def self.data
73
74
  db = {}
74
75
  db['extnames'] = {}
76
+ db['interpreters'] = {}
75
77
  db['filenames'] = {}
76
78
 
77
79
  each do |sample|
@@ -85,6 +87,14 @@ module Linguist
85
87
  end
86
88
  end
87
89
 
90
+ if sample[:interpreter]
91
+ db['interpreters'][language_name] ||= []
92
+ if !db['interpreters'][language_name].include?(sample[:interpreter])
93
+ db['interpreters'][language_name] << sample[:interpreter]
94
+ db['interpreters'][language_name].sort!
95
+ end
96
+ end
97
+
88
98
  if sample[:filename]
89
99
  db['filenames'][language_name] ||= []
90
100
  db['filenames'][language_name] << sample[:filename]
@@ -100,4 +110,40 @@ module Linguist
100
110
  db
101
111
  end
102
112
  end
113
+
114
+ # Used to retrieve the interpreter from the shebang line of a file's
115
+ # data.
116
+ def self.interpreter_from_shebang(data)
117
+ lines = data.lines.to_a
118
+
119
+ if lines.any? && (match = lines[0].match(/(.+)\n?/)) && (bang = match[0]) =~ /^#!/
120
+ bang.sub!(/^#! /, '#!')
121
+ tokens = bang.split(' ')
122
+ pieces = tokens.first.split('/')
123
+
124
+ if pieces.size > 1
125
+ script = pieces.last
126
+ else
127
+ script = pieces.first.sub('#!', '')
128
+ end
129
+
130
+ script = script == 'env' ? tokens[1] : script
131
+
132
+ # "python2.6" -> "python"
133
+ if script =~ /((?:\d+\.?)+)/
134
+ script.sub! $1, ''
135
+ end
136
+
137
+ # Check for multiline shebang hacks that call `exec`
138
+ if script == 'sh' &&
139
+ lines[0...5].any? { |l| l.match(/exec (\w+).+\$0.+\$@/) }
140
+ script = $1
141
+ end
142
+
143
+ script
144
+ else
145
+ nil
146
+ end
147
+ end
148
+
103
149
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: github-linguist
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.10.0
4
+ version: 2.10.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-04 00:00:00.000000000 Z
11
+ date: 2013-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: charlock_holmes