searchlink 2.3.59
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/searchlink +84 -0
- data/lib/searchlink/array.rb +7 -0
- data/lib/searchlink/config.rb +230 -0
- data/lib/searchlink/curl/html.rb +482 -0
- data/lib/searchlink/curl/json.rb +90 -0
- data/lib/searchlink/curl.rb +7 -0
- data/lib/searchlink/help.rb +103 -0
- data/lib/searchlink/output.rb +270 -0
- data/lib/searchlink/parse.rb +668 -0
- data/lib/searchlink/plist.rb +213 -0
- data/lib/searchlink/search.rb +70 -0
- data/lib/searchlink/searches/amazon.rb +25 -0
- data/lib/searchlink/searches/applemusic.rb +123 -0
- data/lib/searchlink/searches/bitly.rb +50 -0
- data/lib/searchlink/searches/definition.rb +67 -0
- data/lib/searchlink/searches/duckduckgo.rb +167 -0
- data/lib/searchlink/searches/github.rb +245 -0
- data/lib/searchlink/searches/google.rb +67 -0
- data/lib/searchlink/searches/helpers/chromium.rb +318 -0
- data/lib/searchlink/searches/helpers/firefox.rb +135 -0
- data/lib/searchlink/searches/helpers/safari.rb +133 -0
- data/lib/searchlink/searches/history.rb +166 -0
- data/lib/searchlink/searches/hook.rb +77 -0
- data/lib/searchlink/searches/itunes.rb +97 -0
- data/lib/searchlink/searches/lastfm.rb +41 -0
- data/lib/searchlink/searches/lyrics.rb +91 -0
- data/lib/searchlink/searches/pinboard.rb +183 -0
- data/lib/searchlink/searches/social.rb +105 -0
- data/lib/searchlink/searches/software.rb +27 -0
- data/lib/searchlink/searches/spelling.rb +59 -0
- data/lib/searchlink/searches/spotlight.rb +28 -0
- data/lib/searchlink/searches/stackoverflow.rb +31 -0
- data/lib/searchlink/searches/tmdb.rb +52 -0
- data/lib/searchlink/searches/twitter.rb +46 -0
- data/lib/searchlink/searches/wikipedia.rb +33 -0
- data/lib/searchlink/searches/youtube.rb +48 -0
- data/lib/searchlink/searches.rb +194 -0
- data/lib/searchlink/semver.rb +140 -0
- data/lib/searchlink/string.rb +469 -0
- data/lib/searchlink/url.rb +153 -0
- data/lib/searchlink/util.rb +87 -0
- data/lib/searchlink/version.rb +93 -0
- data/lib/searchlink/which.rb +175 -0
- data/lib/searchlink.rb +66 -0
- data/lib/tokens.rb +3 -0
- metadata +299 -0
@@ -0,0 +1,270 @@
|
|
1
|
+
module SL
|
2
|
+
class << self
|
3
|
+
attr_writer :titleize, :clipboard, :output, :footer, :line_num,
|
4
|
+
:match_column, :match_length, :originput, :errors, :report, :printout
|
5
|
+
|
6
|
+
# Whether or not to add a title to the output
|
7
|
+
def titleize
|
8
|
+
@titleize ||= false
|
9
|
+
end
|
10
|
+
|
11
|
+
# Whether or not to copy results to clipbpard
|
12
|
+
def clipboard
|
13
|
+
@clipboard ||= false
|
14
|
+
end
|
15
|
+
|
16
|
+
# Whether or not to echo results to STDOUT as they're created
|
17
|
+
def printout
|
18
|
+
@printout ||= false
|
19
|
+
end
|
20
|
+
|
21
|
+
# Stores the generated output
|
22
|
+
def output
|
23
|
+
@output ||= []
|
24
|
+
end
|
25
|
+
|
26
|
+
# Stores the generated debug report
|
27
|
+
def report
|
28
|
+
@report ||= []
|
29
|
+
end
|
30
|
+
|
31
|
+
# Stores the footer with reference links and footnotes
|
32
|
+
def footer
|
33
|
+
@footer ||= []
|
34
|
+
end
|
35
|
+
|
36
|
+
# Tracks the line number of each link match for debug output
|
37
|
+
def line_num
|
38
|
+
@line_num ||= 0
|
39
|
+
end
|
40
|
+
|
41
|
+
# Tracks the column of each link match for debug output
|
42
|
+
def match_column
|
43
|
+
@match_column ||= 0
|
44
|
+
end
|
45
|
+
|
46
|
+
# Tracks the length of each link match for debug output
|
47
|
+
def match_length
|
48
|
+
@match_length ||= 0
|
49
|
+
end
|
50
|
+
|
51
|
+
# Stores the original input
|
52
|
+
def originput
|
53
|
+
@originput ||= ''
|
54
|
+
end
|
55
|
+
|
56
|
+
# Stores generated errors
|
57
|
+
def errors
|
58
|
+
@errors ||= {}
|
59
|
+
end
|
60
|
+
|
61
|
+
# Posts macOS notifications
|
62
|
+
#
|
63
|
+
# @param str The title of the notification
|
64
|
+
# @param sub The text of the notification
|
65
|
+
#
|
66
|
+
def notify(str, sub)
|
67
|
+
return unless SL.config['notifications']
|
68
|
+
|
69
|
+
`osascript -e 'display notification "SearchLink" with title "#{str}" subtitle "#{sub}"'`
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# The SL module provides methods for creating and manipulating links.
|
75
|
+
module SL
|
76
|
+
class << self
|
77
|
+
# Creates a link of the specified type with the given
|
78
|
+
# text, url, and title.
|
79
|
+
#
|
80
|
+
# @param type [Symbol] The type of link to
|
81
|
+
# create.
|
82
|
+
# @param text [String] The text of the
|
83
|
+
# link.
|
84
|
+
# @param url [String] The URL of the link.
|
85
|
+
# @param title [String] The title of the
|
86
|
+
# link.
|
87
|
+
# @param force_title [Boolean] Whether to force
|
88
|
+
# the title to be included.
|
89
|
+
#
|
90
|
+
# @return [String] The link.
|
91
|
+
#
|
92
|
+
def make_link(type, text, url, title: false, force_title: false)
|
93
|
+
title = title.gsub(/\P{Print}|\p{Cf}/, '') if title
|
94
|
+
text = title || SL::URL.title(url) if SL.titleize && (!text || text.strip.empty?)
|
95
|
+
text = text ? text.strip : title
|
96
|
+
title = title && (SL.config['include_titles'] || force_title) ? %( "#{title.clean}") : ''
|
97
|
+
|
98
|
+
title.gsub!(/[ \t]+/, ' ')
|
99
|
+
|
100
|
+
case type.to_sym
|
101
|
+
when :ref_title
|
102
|
+
%(\n[#{text}]: #{url}#{title})
|
103
|
+
when :ref_link
|
104
|
+
%([#{text}][#{url}])
|
105
|
+
when :inline
|
106
|
+
image = url =~ /\.(gif|jpe?g|png|webp)$/ ? '!' : ''
|
107
|
+
%(#{image}[#{text}](#{url}#{title}))
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# Adds the given string to the output.
|
112
|
+
#
|
113
|
+
# @param str [String] The string to add.
|
114
|
+
#
|
115
|
+
# @return [nil]
|
116
|
+
#
|
117
|
+
def add_output(str)
|
118
|
+
print str if SL.printout && !SL.clipboard
|
119
|
+
SL.output << str
|
120
|
+
end
|
121
|
+
|
122
|
+
# Adds the given string to the footer.
|
123
|
+
#
|
124
|
+
# @param str [String] The string to add.
|
125
|
+
#
|
126
|
+
# @return [nil]
|
127
|
+
#
|
128
|
+
def add_footer(str)
|
129
|
+
SL.footer ||= []
|
130
|
+
SL.footer.push(str.strip)
|
131
|
+
end
|
132
|
+
|
133
|
+
# Prints the footer.
|
134
|
+
#
|
135
|
+
# @return [String] The footer.
|
136
|
+
#
|
137
|
+
def print_footer
|
138
|
+
unless SL.footer.empty?
|
139
|
+
|
140
|
+
footnotes = []
|
141
|
+
SL.footer.delete_if do |note|
|
142
|
+
note.strip!
|
143
|
+
case note
|
144
|
+
when /^\[\^.+?\]/
|
145
|
+
footnotes.push(note)
|
146
|
+
true
|
147
|
+
when /^\s*$/
|
148
|
+
true
|
149
|
+
else
|
150
|
+
false
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
output = SL.footer.sort.join("\n").strip
|
155
|
+
output += "\n\n" if !output.empty? && !footnotes.empty?
|
156
|
+
output += footnotes.join("\n\n") unless footnotes.empty?
|
157
|
+
return output.gsub(/\n{3,}/, "\n\n")
|
158
|
+
end
|
159
|
+
|
160
|
+
''
|
161
|
+
end
|
162
|
+
|
163
|
+
# Adds the given string to the report.
|
164
|
+
#
|
165
|
+
# @param str [String] The string to add.
|
166
|
+
#
|
167
|
+
# @return [nil]
|
168
|
+
#
|
169
|
+
def add_report(str)
|
170
|
+
return unless SL.config['report']
|
171
|
+
|
172
|
+
unless SL.line_num.nil?
|
173
|
+
position = "#{SL.line_num}:"
|
174
|
+
position += SL.match_column.nil? ? '0:' : "#{SL.match_column}:"
|
175
|
+
position += SL.match_length.nil? ? '0' : SL.match_length.to_s
|
176
|
+
end
|
177
|
+
SL.report.push("(#{position}): #{str}")
|
178
|
+
warn "(#{position}): #{str}" unless SILENT
|
179
|
+
end
|
180
|
+
|
181
|
+
# Adds the given string to the errors.
|
182
|
+
#
|
183
|
+
# @param type [Symbol] The type of error.
|
184
|
+
# @param str [String] The string to add.
|
185
|
+
#
|
186
|
+
# @return [nil]
|
187
|
+
#
|
188
|
+
def add_error(type, str)
|
189
|
+
return unless SL.config['debug']
|
190
|
+
|
191
|
+
unless SL.line_num.nil?
|
192
|
+
position = "#{SL.line_num}:"
|
193
|
+
position += SL.match_column.nil? ? '0:' : "#{SL.match_column}:"
|
194
|
+
position += SL.match_length.nil? ? '0' : SL.match_length.to_s
|
195
|
+
end
|
196
|
+
SL.errors[type] ||= []
|
197
|
+
SL.errors[type].push("(#{position}): #{str}")
|
198
|
+
end
|
199
|
+
|
200
|
+
# Prints the report.
|
201
|
+
#
|
202
|
+
# @return [String] The report.
|
203
|
+
#
|
204
|
+
def print_report
|
205
|
+
return if (SL.config['inline'] && SL.originput.split(/\n/).length == 1) || SL.clipboard
|
206
|
+
|
207
|
+
return if SL.report.empty?
|
208
|
+
|
209
|
+
out = "\n<!-- Report:\n#{SL.report.join("\n")}\n-->\n"
|
210
|
+
add_output out
|
211
|
+
end
|
212
|
+
|
213
|
+
# Prints the errors.
|
214
|
+
#
|
215
|
+
# @param type [String] The type of errors.
|
216
|
+
#
|
217
|
+
# @return [String] The errors.
|
218
|
+
#
|
219
|
+
def print_errors(type = 'Errors')
|
220
|
+
return if SL.errors.empty?
|
221
|
+
|
222
|
+
out = ''
|
223
|
+
inline = if SL.originput.split(/\n/).length > 1
|
224
|
+
false
|
225
|
+
else
|
226
|
+
SL.config['inline'] || SL.originput.split(/\n/).length == 1
|
227
|
+
end
|
228
|
+
|
229
|
+
SL.errors.each do |k, v|
|
230
|
+
next if v.empty?
|
231
|
+
|
232
|
+
v.each_with_index do |err, i|
|
233
|
+
out += "(#{k}) #{err}"
|
234
|
+
out += if inline
|
235
|
+
i == v.length - 1 ? ' | ' : ', '
|
236
|
+
else
|
237
|
+
"\n"
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
unless out == ''
|
243
|
+
sep = inline ? ' ' : "\n"
|
244
|
+
out.sub!(/\| /, '')
|
245
|
+
out = "#{sep}<!-- #{type}:#{sep}#{out}-->#{sep}"
|
246
|
+
end
|
247
|
+
if SL.clipboard
|
248
|
+
warn out
|
249
|
+
else
|
250
|
+
add_output out
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
# Prints or copies the given text.
|
255
|
+
#
|
256
|
+
# @param text [String] The text to print or copy.
|
257
|
+
#
|
258
|
+
# @return [nil]
|
259
|
+
#
|
260
|
+
def print_or_copy(text)
|
261
|
+
# Process.exit unless text
|
262
|
+
if SL.clipboard
|
263
|
+
`echo #{Shellwords.escape(text)}|tr -d "\n"|pbcopy`
|
264
|
+
print SL.originput
|
265
|
+
else
|
266
|
+
print text
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
270
|
+
end
|