searchlink 2.3.74 → 2.3.76
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/searchlink/config.rb +23 -23
- data/lib/searchlink/curl/html.rb +38 -38
- data/lib/searchlink/curl/json.rb +19 -17
- data/lib/searchlink/curl.rb +2 -2
- data/lib/searchlink/exceptions.rb +2 -2
- data/lib/searchlink/help.rb +13 -13
- data/lib/searchlink/output.rb +21 -21
- data/lib/searchlink/parse.rb +113 -108
- data/lib/searchlink/plist.rb +11 -11
- data/lib/searchlink/script_plugin.rb +10 -10
- data/lib/searchlink/search.rb +6 -6
- data/lib/searchlink/searches/amazon.rb +4 -4
- data/lib/searchlink/searches/applemusic.rb +28 -28
- data/lib/searchlink/searches/bitly.rb +11 -11
- data/lib/searchlink/searches/definition.rb +7 -7
- data/lib/searchlink/searches/duckduckgo.rb +31 -27
- data/lib/searchlink/searches/github.rb +48 -48
- data/lib/searchlink/searches/google.rb +16 -16
- data/lib/searchlink/searches/helpers/chromium.rb +46 -46
- data/lib/searchlink/searches/helpers/firefox.rb +20 -20
- data/lib/searchlink/searches/helpers/safari.rb +14 -14
- data/lib/searchlink/searches/history.rb +78 -78
- data/lib/searchlink/searches/hook.rb +5 -5
- data/lib/searchlink/searches/itunes.rb +37 -37
- data/lib/searchlink/searches/lastfm.rb +13 -13
- data/lib/searchlink/searches/linkding.rb +14 -14
- data/lib/searchlink/searches/lyrics.rb +11 -11
- data/lib/searchlink/searches/pinboard.rb +35 -35
- data/lib/searchlink/searches/social.rb +45 -56
- data/lib/searchlink/searches/software.rb +4 -4
- data/lib/searchlink/searches/spelling.rb +10 -10
- data/lib/searchlink/searches/spotlight.rb +4 -4
- data/lib/searchlink/searches/stackoverflow.rb +5 -5
- data/lib/searchlink/searches/tmdb.rb +17 -17
- data/lib/searchlink/searches/twitter.rb +8 -8
- data/lib/searchlink/searches/wikipedia.rb +4 -4
- data/lib/searchlink/searches/youtube.rb +7 -7
- data/lib/searchlink/searches.rb +16 -16
- data/lib/searchlink/semver.rb +4 -4
- data/lib/searchlink/string.rb +55 -55
- data/lib/searchlink/url.rb +30 -32
- data/lib/searchlink/util.rb +3 -3
- data/lib/searchlink/version.rb +19 -21
- data/lib/searchlink/which.rb +5 -5
- data/lib/searchlink.rb +31 -31
- metadata +31 -18
- data/lib/tokens.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be4b0bed0468171691989a3253680ad36237420963132e4ee7696b4ca529be78
|
4
|
+
data.tar.gz: d83e1b707146106f42557b551368831a6d09bb953ab94c9f52008f01f113978c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 538c8a40d2faf7deb9a228a4f05804a80dd84ee59fb1aadfc43d2e903bb7529e03358d07dc7f559508a57be5fab13ede66b342931f17e640039123f8feefe4c2
|
7
|
+
data.tar.gz: 39c52a0f44a142fa5e165bb5b2f05cc4e81446ef4ff04ae369e9cf6f181c401d8602f6bbf4958f49db4d49714beae51d77bead32ed16cff9b5ccd1ef183d048d
|
data/lib/searchlink/config.rb
CHANGED
@@ -20,8 +20,8 @@ module SL
|
|
20
20
|
# Values found in ~/.searchlink will override defaults in
|
21
21
|
# this script
|
22
22
|
def config_file
|
23
|
-
old_style = File.expand_path(
|
24
|
-
new_style = File.expand_path(
|
23
|
+
old_style = File.expand_path("~/.searchlink")
|
24
|
+
new_style = File.expand_path("~/.config/searchlink/config.yaml")
|
25
25
|
if File.exist?(old_style) && !File.exist?(new_style)
|
26
26
|
old_style
|
27
27
|
else
|
@@ -158,7 +158,7 @@ module SL
|
|
158
158
|
|
159
159
|
ENDCONFIG
|
160
160
|
|
161
|
-
File.open(config_file,
|
161
|
+
File.open(config_file, "w") do |f|
|
162
162
|
f.puts default_config
|
163
163
|
end
|
164
164
|
end
|
@@ -166,45 +166,45 @@ module SL
|
|
166
166
|
config = YAML.load_file(config_file)
|
167
167
|
|
168
168
|
# set to true to have an HTML comment inserted showing any errors
|
169
|
-
config[
|
169
|
+
config["debug"] ||= false
|
170
170
|
|
171
171
|
# set to true to get a verbose report at the end of multi-line processing
|
172
|
-
config[
|
172
|
+
config["report"] ||= false
|
173
173
|
|
174
|
-
config[
|
174
|
+
config["backup"] = true unless config.key? "backup"
|
175
175
|
|
176
|
-
config[
|
176
|
+
config["timeout"] ||= 15
|
177
177
|
|
178
178
|
# set to true to force inline links
|
179
|
-
config[
|
179
|
+
config["inline"] ||= false
|
180
180
|
|
181
181
|
# set to true to add titles to links based on site title
|
182
|
-
config[
|
182
|
+
config["include_titles"] ||= false
|
183
183
|
|
184
184
|
# set to true to remove SEO elements from page titles
|
185
|
-
config[
|
185
|
+
config["remove_seo"] ||= false
|
186
186
|
|
187
187
|
# set to true to use page title as link text when empty
|
188
|
-
config[
|
188
|
+
config["empty_uses_page_title"] ||= false
|
189
189
|
|
190
190
|
# change this to set a specific country for search (default US)
|
191
|
-
config[
|
191
|
+
config["country_code"] ||= "US"
|
192
192
|
|
193
193
|
# set to true to include a random string in ref titles
|
194
194
|
# allows running SearchLink multiple times w/out conflicts
|
195
|
-
config[
|
195
|
+
config["prefix_random"] = false unless config["prefix_random"]
|
196
196
|
|
197
|
-
config[
|
197
|
+
config["social_template"] ||= "%service%/%user%"
|
198
198
|
|
199
199
|
# append affiliate link info to iTunes urls, empty quotes for none
|
200
200
|
# example:
|
201
201
|
# $itunes_affiliate = "&at=10l4tL&ct=searchlink"
|
202
|
-
config[
|
202
|
+
config["itunes_affiliate"] ||= "&at=10l4tL&ct=searchlink"
|
203
203
|
|
204
204
|
# to create Amazon affiliate links, set amazon_partner to your amazon
|
205
205
|
# affiliate tag
|
206
206
|
# amazon_partner: "bretttercom-20"
|
207
|
-
config[
|
207
|
+
config["amazon_partner"] ||= ""
|
208
208
|
|
209
209
|
# To create custom abbreviations for Google Site Searches,
|
210
210
|
# add to (or replace) the hash below.
|
@@ -212,18 +212,18 @@ module SL
|
|
212
212
|
# This allows you, for example to use [search term](!bt)
|
213
213
|
# as a shortcut to search brettterpstra.com. Keys in this
|
214
214
|
# hash can override existing search triggers.
|
215
|
-
config[
|
216
|
-
|
217
|
-
|
215
|
+
config["custom_site_searches"] ||= {
|
216
|
+
"bt" => "brettterpstra.com",
|
217
|
+
"imdb" => "imdb.com"
|
218
218
|
}
|
219
219
|
|
220
220
|
# confirm existence of links generated from custom search replacements
|
221
|
-
config[
|
221
|
+
config["validate_links"] ||= false
|
222
222
|
|
223
223
|
# use notification center to show progress
|
224
|
-
config[
|
225
|
-
config[
|
226
|
-
config[
|
224
|
+
config["notifications"] ||= false
|
225
|
+
config["pinboard_api_key"] ||= false
|
226
|
+
config["google_api_key"] ||= false
|
227
227
|
|
228
228
|
SL.line_num = nil
|
229
229
|
SL.match_column = nil
|
data/lib/searchlink/curl/html.rb
CHANGED
@@ -4,7 +4,7 @@ module Curl
|
|
4
4
|
# String helpers
|
5
5
|
class ::String
|
6
6
|
def remove_entities
|
7
|
-
gsub(/ /,
|
7
|
+
gsub(/ /, " ")
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
@@ -24,7 +24,7 @@ module Curl
|
|
24
24
|
## @return [HTMLCurl] new page object
|
25
25
|
##
|
26
26
|
def initialize(url, headers: nil, headers_only: false, compressed: false)
|
27
|
-
@curl = TTY::Which.which(
|
27
|
+
@curl = TTY::Which.which("curl")
|
28
28
|
res = curl_html(url, headers: headers, headers_only: headers_only, compressed: compressed)
|
29
29
|
@url = res[:url]
|
30
30
|
@code = res[:code]
|
@@ -34,8 +34,8 @@ module Curl
|
|
34
34
|
@head = res[:head] unless res[:head].nil?
|
35
35
|
@body = reencode(res[:body])
|
36
36
|
@source = res[:source]
|
37
|
-
@title = @meta[
|
38
|
-
@description = @meta[
|
37
|
+
@title = @meta["og:title"] || @meta["title"] unless @meta.nil?
|
38
|
+
@description = @meta["og:description"] || @meta["description"] unless @meta.nil?
|
39
39
|
@body_links = content_links
|
40
40
|
@body_images = content_images
|
41
41
|
end
|
@@ -85,7 +85,7 @@ module Curl
|
|
85
85
|
m = tag_source.to_enum(:scan, /(\S+)=(['"])(.*?)\2/).map { Regexp.last_match }
|
86
86
|
attrs = m.each_with_object({}) { |at, a| a[at[1]] = at[3] }
|
87
87
|
tags = tag_source.match(/<.*?>(?<content>.*?)</)
|
88
|
-
contents = tags.nil? ? nil : tags[
|
88
|
+
contents = tags.nil? ? nil : tags["content"]
|
89
89
|
{
|
90
90
|
tag: tag,
|
91
91
|
source: tag_source,
|
@@ -145,7 +145,7 @@ module Curl
|
|
145
145
|
next unless @meta.key?(src)
|
146
146
|
|
147
147
|
output << {
|
148
|
-
type:
|
148
|
+
type: "opengraph",
|
149
149
|
attrs: nil,
|
150
150
|
src: @meta[src]
|
151
151
|
}
|
@@ -167,14 +167,14 @@ module Curl
|
|
167
167
|
end
|
168
168
|
end
|
169
169
|
output << {
|
170
|
-
type:
|
170
|
+
type: "srcset",
|
171
171
|
attrs: img[:attrs],
|
172
172
|
images: srcset
|
173
173
|
}
|
174
174
|
end
|
175
175
|
when /img/
|
176
176
|
output << {
|
177
|
-
type:
|
177
|
+
type: "img",
|
178
178
|
src: img[:attrs].filter { |a| a[:key] =~ /src/i }.first[:value],
|
179
179
|
attrs: img[:attrs]
|
180
180
|
}
|
@@ -190,7 +190,7 @@ module Curl
|
|
190
190
|
[
|
191
191
|
%(<HTMLCurl: @code="#{@code}" @url="#{@url}" @title="#{@title}"),
|
192
192
|
%(@description=#{@description} @headers:#{headers} @meta:#{meta} @links:#{links}>)
|
193
|
-
].join(
|
193
|
+
].join(" ")
|
194
194
|
end
|
195
195
|
|
196
196
|
##
|
@@ -204,14 +204,14 @@ module Curl
|
|
204
204
|
res = []
|
205
205
|
headlines = @body.to_enum(:scan, %r{<h(?<level>#{level})(?<tag> .*?)?>(?<text>.*?)</h#{level}>}i).map { Regexp.last_match }
|
206
206
|
headlines.each do |m|
|
207
|
-
headline = { level: m[
|
208
|
-
if m[
|
207
|
+
headline = { level: m["level"] }
|
208
|
+
if m["tag"].nil?
|
209
209
|
attrs = nil
|
210
210
|
else
|
211
|
-
attrs = m[
|
212
|
-
attrs.each { |a| headline[a[
|
211
|
+
attrs = m["tag"].to_enum(:scan, /(?<attr>\w+)=(?<quot>["'])(?<content>.*?)\k<quot>/).map { Regexp.last_match }
|
212
|
+
attrs.each { |a| headline[a["attr"].to_sym] = a["content"] }
|
213
213
|
end
|
214
|
-
headline[:text] = m[
|
214
|
+
headline[:text] = m["text"].remove_entities
|
215
215
|
res << headline
|
216
216
|
end
|
217
217
|
res
|
@@ -247,20 +247,20 @@ module Curl
|
|
247
247
|
<(?<tag>(?!</)[a-z0-9]+)(?<attrs>\s[^>]+)?
|
248
248
|
(?:\s*/>|>(?<content>.*?)</\k<tag>>)}).map { Regexp.last_match }
|
249
249
|
res.map do |tag|
|
250
|
-
if tag[
|
250
|
+
if tag["attrs"].nil?
|
251
251
|
attrs = nil
|
252
252
|
else
|
253
|
-
attrs = tag[
|
253
|
+
attrs = tag["attrs"].strip.to_enum(:scan, /(?ix)
|
254
254
|
(?<key>[@a-z0-9-]+)(?:=(?<quot>["'])
|
255
255
|
(?<value>[^"']+)\k<quot>|[ >])?/i).map { Regexp.last_match }
|
256
|
-
attrs.map! { |a| { key: a[
|
256
|
+
attrs.map! { |a| { key: a["key"], value: a["key"] =~ /^(class|rel)$/ ? a["value"].split(/ /) : a["value"] } }
|
257
257
|
end
|
258
258
|
{
|
259
|
-
tag: tag[
|
259
|
+
tag: tag["tag"],
|
260
260
|
source: tag.to_s,
|
261
261
|
attrs: attrs,
|
262
|
-
content: tag[
|
263
|
-
tags: content_tags(tag[
|
262
|
+
content: tag["content"],
|
263
|
+
tags: content_tags(tag["content"])
|
264
264
|
}
|
265
265
|
end
|
266
266
|
end
|
@@ -275,10 +275,10 @@ module Curl
|
|
275
275
|
def meta_tags(head)
|
276
276
|
meta = {}
|
277
277
|
title = head.match(%r{(?<=<title>)(.*?)(?=</title>)})
|
278
|
-
meta[
|
278
|
+
meta["title"] = title.nil? ? nil : title[1]
|
279
279
|
refresh = head.match(/http-equiv=(['"])refresh\1(.*?)>/)
|
280
280
|
url = refresh.nil? ? nil : refresh[2].match(/url=(.*?)['"]/)
|
281
|
-
meta[
|
281
|
+
meta["refresh_url"] = url
|
282
282
|
meta_tags = head.scan(/<meta.*?>/)
|
283
283
|
meta_tags.each do |tag|
|
284
284
|
meta_name = tag.match(/(?:name|property|http-equiv)=(["'])(.*?)\1/)
|
@@ -337,15 +337,15 @@ module Curl
|
|
337
337
|
links = []
|
338
338
|
link_tags = @body.to_enum(:scan, %r{<a (?<tag>.*?)>(?<text>.*?)</a>}).map { Regexp.last_match }
|
339
339
|
link_tags.each do |m|
|
340
|
-
href = m[
|
340
|
+
href = m["tag"].match(/href=(["'])(.*?)\1/)
|
341
341
|
href = href[2] unless href.nil?
|
342
|
-
title = m[
|
342
|
+
title = m["tag"].match(/title=(["'])(.*?)\1/)
|
343
343
|
title = title[2] unless title.nil?
|
344
|
-
rel = m[
|
344
|
+
rel = m["tag"].match(/rel=(["'])(.*?)\1/)
|
345
345
|
rel = rel[2] unless rel.nil?
|
346
|
-
link_class = m[
|
346
|
+
link_class = m["tag"].match(/class=(["'])(.*?)\1/)
|
347
347
|
link_class = link_class[2] unless link_class.nil?
|
348
|
-
text = m[
|
348
|
+
text = m["text"].remove_entities
|
349
349
|
link = {
|
350
350
|
href: href,
|
351
351
|
title: title,
|
@@ -367,9 +367,9 @@ module Curl
|
|
367
367
|
images = []
|
368
368
|
image_tags = @body.to_enum(:scan, %r{<img (?<tag>.*?)/?>}).map { Regexp.last_match }
|
369
369
|
image_tags.each do |m|
|
370
|
-
attrs = m[
|
370
|
+
attrs = m["tag"].to_enum(:scan, /(?<attr>\w+)=(?<quot>["'])(?<content>.*?)\k<quot>/).map { Regexp.last_match }
|
371
371
|
image = {}
|
372
|
-
attrs.each { |a| image[a[
|
372
|
+
attrs.each { |a| image[a["attr"].to_sym] = a["content"] }
|
373
373
|
images << image
|
374
374
|
end
|
375
375
|
images
|
@@ -386,13 +386,13 @@ module Curl
|
|
386
386
|
## @return [Hash] hash of url, code, headers, meta, links, head, body, and source
|
387
387
|
##
|
388
388
|
def curl_html(url, headers: nil, headers_only: false, compressed: false)
|
389
|
-
flags =
|
390
|
-
flags += headers_only ?
|
391
|
-
agent = [
|
392
|
-
|
393
|
-
|
394
|
-
headers = headers.nil? ?
|
395
|
-
compress = compressed ?
|
389
|
+
flags = "SsL"
|
390
|
+
flags += headers_only ? "I" : "i"
|
391
|
+
agent = ["Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us)",
|
392
|
+
"AppleWebKit/533.17.9 (KHTML, like Gecko)",
|
393
|
+
"Version/5.0.2 Mobile/8J2 Safari/6533.18.5"].join(" ")
|
394
|
+
headers = headers.nil? ? "" : headers.map { |h, v| %(-H "#{h}: #{v}") }.join(" ")
|
395
|
+
compress = compressed ? "--compressed" : ""
|
396
396
|
source = `#{@curl} -#{flags} #{compress} #{headers} '#{url}' 2>/dev/null`
|
397
397
|
if source.nil? || source.empty?
|
398
398
|
source = `#{@curl} -#{flags} #{compress} -A "#{agent}" #{headers} '#{url}' 2>/dev/null`
|
@@ -416,7 +416,7 @@ module Curl
|
|
416
416
|
end
|
417
417
|
end
|
418
418
|
|
419
|
-
if headers[
|
419
|
+
if headers["content-type"] =~ /json/
|
420
420
|
return { url: url, code: code, headers: headers, meta: nil, links: nil, head: nil, body: source.strip, source: source.strip, body_links: nil, body_images: nil }
|
421
421
|
end
|
422
422
|
|
@@ -457,7 +457,7 @@ module Curl
|
|
457
457
|
|
458
458
|
# look for a charset in a meta tag in the first 1024 bytes
|
459
459
|
unless encoding
|
460
|
-
data = body[0..1023].gsub(/<!--.*?(-->|\Z)/m,
|
460
|
+
data = body[0..1023].gsub(/<!--.*?(-->|\Z)/m, "")
|
461
461
|
data.scan(/<meta.*?>/im).each do |meta|
|
462
462
|
encoding ||= meta[/charset=["']?([^>]*?)($|["'\s>])/im, 1]
|
463
463
|
end
|
data/lib/searchlink/curl/json.rb
CHANGED
@@ -14,9 +14,9 @@ module Curl
|
|
14
14
|
##
|
15
15
|
## @return [Curl::Json] Curl::Json object with url, code, parsed json, and response headers
|
16
16
|
##
|
17
|
-
def initialize(url, headers: nil, compressed: false, symbolize_names: false)
|
18
|
-
@curl = TTY::Which.which(
|
19
|
-
page = curl_json(url, headers: headers, compressed: compressed, symbolize_names: symbolize_names)
|
17
|
+
def initialize(url, data: nil, headers: nil, compressed: false, symbolize_names: false)
|
18
|
+
@curl = TTY::Which.which("curl")
|
19
|
+
page = curl_json(url, data: data, headers: headers, compressed: compressed, symbolize_names: symbolize_names)
|
20
20
|
@url = page[:url]
|
21
21
|
@code = page[:code]
|
22
22
|
@json = page[:json]
|
@@ -28,10 +28,10 @@ module Curl
|
|
28
28
|
target = json
|
29
29
|
parts.each do |part|
|
30
30
|
target = if part =~ /(?<key>[^\[]+)\[(?<int>\d+)\]/
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
target[key][int.to_i]
|
32
|
+
else
|
33
|
+
target[part]
|
34
|
+
end
|
35
35
|
end
|
36
36
|
|
37
37
|
target
|
@@ -48,14 +48,16 @@ module Curl
|
|
48
48
|
##
|
49
49
|
## @return [Hash] hash of url, code, headers, and parsed json
|
50
50
|
##
|
51
|
-
def curl_json(url, headers: nil, compressed: false, symbolize_names: false)
|
52
|
-
flags =
|
53
|
-
agent = [
|
54
|
-
|
55
|
-
|
56
|
-
headers = headers.nil? ?
|
57
|
-
|
58
|
-
|
51
|
+
def curl_json(url, data: nil, headers: nil, compressed: false, symbolize_names: false)
|
52
|
+
flags = "SsLi"
|
53
|
+
agent = ["Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us)",
|
54
|
+
"AppleWebKit/533.17.9 (KHTML, like Gecko)",
|
55
|
+
"Version/5.0.2 Mobile/8J2 Safari/6533.18.5"].join(" ")
|
56
|
+
headers = headers.nil? ? "" : headers.map { |h, v| %(-H "#{h}: #{v}") }.join(" ")
|
57
|
+
data = data.nil? ? "" : %(-d '#{data}')
|
58
|
+
compress = compressed ? "--compressed" : ""
|
59
|
+
|
60
|
+
source = `#{@curl} -#{flags} #{compress} #{headers} #{data} "#{url}" 2>/dev/null`
|
59
61
|
if source.nil? || source.empty?
|
60
62
|
source = `#{@curl} -#{flags} #{compress} -A "#{agent}" #{headers} '#{url}' 2>/dev/null`
|
61
63
|
end
|
@@ -78,9 +80,9 @@ module Curl
|
|
78
80
|
end
|
79
81
|
end
|
80
82
|
|
81
|
-
json = source.strip.force_encoding(
|
83
|
+
json = source.strip.force_encoding("utf-8")
|
82
84
|
|
83
|
-
json.gsub!(/[\u{1F600}-\u{1F6FF}]/,
|
85
|
+
json.gsub!(/[\u{1F600}-\u{1F6FF}]/, "")
|
84
86
|
|
85
87
|
{ url: url, code: code, headers: headers, json: JSON.parse(json, symbolize_names: symbolize_names) }
|
86
88
|
rescue StandardError => e
|
data/lib/searchlink/curl.rb
CHANGED
@@ -4,7 +4,7 @@ module SL
|
|
4
4
|
# Custom Semantic Versioning error
|
5
5
|
class VersionError < StandardError
|
6
6
|
def initialize(msg)
|
7
|
-
msg = msg ? ": #{msg}" :
|
7
|
+
msg = msg ? ": #{msg}" : ""
|
8
8
|
puts "Versioning error#{msg}"
|
9
9
|
|
10
10
|
super()
|
@@ -17,7 +17,7 @@ module SL
|
|
17
17
|
class PluginError < StandardError
|
18
18
|
def initialize(msg = nil, plugin: nil)
|
19
19
|
plugin = %("#{plugin}") if plugin
|
20
|
-
plugin ||=
|
20
|
+
plugin ||= "plugin"
|
21
21
|
msg = ": #{msg}" if msg
|
22
22
|
puts "Error in #{plugin}#{msg}"
|
23
23
|
|
data/lib/searchlink/help.rb
CHANGED
@@ -65,36 +65,36 @@ module SL
|
|
65
65
|
#{SL::Searches.available_searches}
|
66
66
|
EOHELP
|
67
67
|
|
68
|
-
if SL.config[
|
68
|
+
if SL.config["custom_site_searches"]
|
69
69
|
text += "\n-- [Custom Searches] ----------------------\n"
|
70
|
-
SL.config[
|
70
|
+
SL.config["custom_site_searches"].sort_by { |l, _s| l }.each { |label, site| text += "!#{label}#{label.spacer} #{site}\n" }
|
71
71
|
end
|
72
72
|
text
|
73
73
|
end
|
74
74
|
|
75
75
|
def help_html
|
76
76
|
out = ['<input type="text" id="filter" onkeyup="filterTable()" placeholder="Filter searches">']
|
77
|
-
out <<
|
77
|
+
out << "<h2>Available Searches</h2>"
|
78
78
|
out << SL::Searches.available_searches_html
|
79
|
-
out <<
|
79
|
+
out << "<h2>Custom Searches</h2>"
|
80
80
|
out << '<table id="custom">'
|
81
|
-
out <<
|
82
|
-
out <<
|
83
|
-
SL.config[
|
84
|
-
out <<
|
85
|
-
out <<
|
81
|
+
out << "<thead><td>Shortcut</td><td>Search Type</td></thead>"
|
82
|
+
out << "<tbody>"
|
83
|
+
SL.config["custom_site_searches"].each { |label, site| out << "<tr><td><code>!#{label}</code></td><td>#{site}</td></tr>" }
|
84
|
+
out << "</tbody>"
|
85
|
+
out << "</table>"
|
86
86
|
out.join("\n")
|
87
87
|
end
|
88
88
|
|
89
89
|
def help_dialog
|
90
90
|
text = ["<html><head><style>#{help_css}</style><script>#{help_js}</script></head><body>"]
|
91
|
-
text <<
|
91
|
+
text << "<h1>SearchLink Help</h1>"
|
92
92
|
text << "<p>[#{SL.version_check}] [<a href='https://github.com/ttscoff/searchlink/wiki'>Wiki</a>]</p>"
|
93
93
|
text << help_html
|
94
94
|
text << '<p><a href="https://github.com/ttscoff/searchlink/wiki">Visit the wiki</a> for additional information</p>'
|
95
|
-
text <<
|
96
|
-
html_file = File.expand_path(
|
97
|
-
File.open(html_file,
|
95
|
+
text << "</body>"
|
96
|
+
html_file = File.expand_path("~/.searchlink_searches.html")
|
97
|
+
File.open(html_file, "w") { |f| f.puts text.join("\n") }
|
98
98
|
`open #{html_file}`
|
99
99
|
end
|
100
100
|
|
data/lib/searchlink/output.rb
CHANGED
@@ -52,7 +52,7 @@ module SL
|
|
52
52
|
|
53
53
|
# Stores the original input
|
54
54
|
def originput
|
55
|
-
@originput ||=
|
55
|
+
@originput ||= ""
|
56
56
|
end
|
57
57
|
|
58
58
|
# Stores generated errors
|
@@ -66,7 +66,7 @@ module SL
|
|
66
66
|
# @param subtitle [String] The text of the notification
|
67
67
|
#
|
68
68
|
def notify(title, subtitle)
|
69
|
-
return unless SL.config[
|
69
|
+
return unless SL.config["notifications"]
|
70
70
|
|
71
71
|
title = title.gsub(/"/, '\\"')
|
72
72
|
subtitle = subtitle.gsub(/"/, '\\"')
|
@@ -95,12 +95,12 @@ module SL
|
|
95
95
|
# @return [String] The link.
|
96
96
|
#
|
97
97
|
def make_link(type, text, url, title: false, force_title: false)
|
98
|
-
title = title.gsub(/\P{Print}|\p{Cf}/,
|
98
|
+
title = title.gsub(/\P{Print}|\p{Cf}/, "") if title
|
99
99
|
text = title || SL::URL.title(url) if SL.titleize && (!text || text.strip.empty?)
|
100
100
|
text = text ? text.strip : title
|
101
|
-
title = title && (SL.config[
|
101
|
+
title = title && (SL.config["include_titles"] || force_title) ? %( "#{title.clean}") : ""
|
102
102
|
|
103
|
-
title = title.gsub(/[ \t]+/,
|
103
|
+
title = title.gsub(/[ \t]+/, " ")
|
104
104
|
|
105
105
|
case type.to_sym
|
106
106
|
when :ref_title
|
@@ -108,7 +108,7 @@ module SL
|
|
108
108
|
when :ref_link
|
109
109
|
%([#{text}][#{url}])
|
110
110
|
when :inline
|
111
|
-
image = url =~ /\.(gif|jpe?g|png|webp)$/ ?
|
111
|
+
image = url =~ /\.(gif|jpe?g|png|webp)$/ ? "!" : ""
|
112
112
|
%(#{image}[#{text}](#{url}#{title}))
|
113
113
|
end
|
114
114
|
end
|
@@ -162,7 +162,7 @@ module SL
|
|
162
162
|
return output.gsub(/\n{3,}/, "\n\n")
|
163
163
|
end
|
164
164
|
|
165
|
-
|
165
|
+
""
|
166
166
|
end
|
167
167
|
|
168
168
|
# Adds the given string to the report.
|
@@ -172,12 +172,12 @@ module SL
|
|
172
172
|
# @return [nil]
|
173
173
|
#
|
174
174
|
def add_report(str)
|
175
|
-
return unless SL.config[
|
175
|
+
return unless SL.config["report"]
|
176
176
|
|
177
177
|
unless SL.line_num.nil?
|
178
178
|
position = "#{SL.line_num}:"
|
179
|
-
position += SL.match_column.nil? ?
|
180
|
-
position += SL.match_length.nil? ?
|
179
|
+
position += SL.match_column.nil? ? "0:" : "#{SL.match_column}:"
|
180
|
+
position += SL.match_length.nil? ? "0" : SL.match_length.to_s
|
181
181
|
end
|
182
182
|
SL.report.push("(#{position}): #{str}")
|
183
183
|
warn "(#{position}): #{str}" unless SILENT
|
@@ -191,12 +191,12 @@ module SL
|
|
191
191
|
# @return [nil]
|
192
192
|
#
|
193
193
|
def add_error(type, str)
|
194
|
-
return unless SL.config[
|
194
|
+
return unless SL.config["debug"]
|
195
195
|
|
196
196
|
unless SL.line_num.nil?
|
197
197
|
position = "#{SL.line_num}:"
|
198
|
-
position += SL.match_column.nil? ?
|
199
|
-
position += SL.match_length.nil? ?
|
198
|
+
position += SL.match_column.nil? ? "0:" : "#{SL.match_column}:"
|
199
|
+
position += SL.match_length.nil? ? "0" : SL.match_length.to_s
|
200
200
|
end
|
201
201
|
SL.errors[type] ||= []
|
202
202
|
SL.errors[type].push("(#{position}): #{str}")
|
@@ -207,7 +207,7 @@ module SL
|
|
207
207
|
# @return [String] The report.
|
208
208
|
#
|
209
209
|
def print_report
|
210
|
-
return if (SL.config[
|
210
|
+
return if (SL.config["inline"] && SL.originput.split(/\n/).length == 1) || SL.clipboard
|
211
211
|
|
212
212
|
return if SL.report.empty?
|
213
213
|
|
@@ -221,14 +221,14 @@ module SL
|
|
221
221
|
#
|
222
222
|
# @return [String] The errors.
|
223
223
|
#
|
224
|
-
def print_errors(type =
|
224
|
+
def print_errors(type = "Errors")
|
225
225
|
return if SL.errors.empty?
|
226
226
|
|
227
|
-
out =
|
227
|
+
out = ""
|
228
228
|
inline = if SL.originput.split(/\n/).length > 1
|
229
229
|
false
|
230
230
|
else
|
231
|
-
SL.config[
|
231
|
+
SL.config["inline"] || SL.originput.split(/\n/).length == 1
|
232
232
|
end
|
233
233
|
|
234
234
|
SL.errors.each do |k, v|
|
@@ -237,16 +237,16 @@ module SL
|
|
237
237
|
v.each_with_index do |err, i|
|
238
238
|
out += "(#{k}) #{err}"
|
239
239
|
out += if inline
|
240
|
-
i == v.length - 1 ?
|
240
|
+
i == v.length - 1 ? " | " : ", "
|
241
241
|
else
|
242
242
|
"\n"
|
243
243
|
end
|
244
244
|
end
|
245
245
|
end
|
246
246
|
|
247
|
-
unless out ==
|
248
|
-
sep = inline ?
|
249
|
-
out.sub!(/\| /,
|
247
|
+
unless out == ""
|
248
|
+
sep = inline ? " " : "\n"
|
249
|
+
out.sub!(/\| /, "")
|
250
250
|
out = "#{sep}<!-- #{type}:#{sep}#{out}-->#{sep}"
|
251
251
|
end
|
252
252
|
if SL.clipboard
|