searchlink 2.3.74 → 2.3.76
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
data/lib/searchlink/parse.rb
CHANGED
|
@@ -12,7 +12,7 @@ module SL
|
|
|
12
12
|
#
|
|
13
13
|
def parse_arguments(string, opt = {})
|
|
14
14
|
input = string.dup
|
|
15
|
-
return
|
|
15
|
+
return "" if input.nil?
|
|
16
16
|
|
|
17
17
|
skip_flags = opt[:only_meta] || false
|
|
18
18
|
no_restore = opt[:no_restore] || false
|
|
@@ -24,8 +24,12 @@ module SL
|
|
|
24
24
|
options.each do |o|
|
|
25
25
|
if input =~ /^ *#{o}:\s+(\S+)$/
|
|
26
26
|
val = Regexp.last_match(1).strip
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
|
|
28
|
+
if val.is_a?(String)
|
|
29
|
+
value = true if val =~ /true/i
|
|
30
|
+
value = false if val =~ /false/i
|
|
31
|
+
end
|
|
32
|
+
val = value if value
|
|
29
33
|
SL.config[o] = val
|
|
30
34
|
warn "\r\033[0KGlobal config: #{o} = #{SL.config[o]}\n" unless SILENT
|
|
31
35
|
end
|
|
@@ -37,11 +41,11 @@ module SL
|
|
|
37
41
|
|
|
38
42
|
unless SL.prev_config.key? o
|
|
39
43
|
SL.prev_config[o] = SL.config[o]
|
|
40
|
-
bool = Regexp.last_match(1).nil? || Regexp.last_match(1) ==
|
|
44
|
+
bool = Regexp.last_match(1).nil? || Regexp.last_match(1) == "" ? true : false
|
|
41
45
|
SL.config[o] = bool
|
|
42
46
|
$stderr.print "\r\033[0KLine config: #{o} = #{SL.config[o]}\n" unless SILENT
|
|
43
47
|
end
|
|
44
|
-
input.sub!(/\s?--(no-)?#{o}/,
|
|
48
|
+
input.sub!(/\s?--(no-)?#{o}/, "")
|
|
45
49
|
end
|
|
46
50
|
end
|
|
47
51
|
SL.clipboard ? string : input
|
|
@@ -60,32 +64,32 @@ module SL
|
|
|
60
64
|
help_dialog
|
|
61
65
|
else
|
|
62
66
|
$stdout.puts SL.version_check.to_s
|
|
63
|
-
$stdout.puts
|
|
67
|
+
$stdout.puts "See https://github.com/ttscoff/searchlink/wiki for help"
|
|
64
68
|
end
|
|
65
69
|
print input
|
|
66
70
|
when /^!?(wiki|docs)$/i
|
|
67
|
-
warn
|
|
71
|
+
warn "Opening wiki in browser"
|
|
68
72
|
`open https://github.com/ttscoff/searchlink/wiki`
|
|
69
73
|
when /^!?v(er(s(ion)?)?)?$/
|
|
70
74
|
print "[#{SL.version_check}]"
|
|
71
75
|
when /^!?up(date|grade)$/
|
|
72
76
|
SL.update_searchlink
|
|
73
|
-
print SL.output.join(
|
|
77
|
+
print SL.output.join("")
|
|
74
78
|
end
|
|
75
79
|
Process.exit 0
|
|
76
80
|
end
|
|
77
81
|
|
|
78
82
|
def create_footnote(mtch)
|
|
79
|
-
if mtch[1].nil? || mtch[1] ==
|
|
83
|
+
if mtch[1].nil? || mtch[1] == ""
|
|
80
84
|
match
|
|
81
85
|
else
|
|
82
86
|
note = mtch[1].strip
|
|
83
87
|
@footnote_counter += 1
|
|
84
88
|
ref = if !@link_text.empty? && @link_text.scan(/\s/).empty?
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
+
@link_text
|
|
90
|
+
else
|
|
91
|
+
format("%<p>sfn%<c>04d", p: @prefix, c: @footnote_counter)
|
|
92
|
+
end
|
|
89
93
|
SL.add_footer "[^#{ref}]: #{note}"
|
|
90
94
|
res = "[^#{ref}]"
|
|
91
95
|
@cursor_difference += (SL.match_length - res.length)
|
|
@@ -106,7 +110,7 @@ module SL
|
|
|
106
110
|
SL.add_footer SL.make_link(:ref_title, @link_text, @url, title: title, force_title: false)
|
|
107
111
|
end
|
|
108
112
|
@delete_line = true
|
|
109
|
-
elsif SL.config[
|
|
113
|
+
elsif SL.config["inline"]
|
|
110
114
|
res = SL.make_link(:inline, @link_text, @url, title: title, force_title: false)
|
|
111
115
|
@cursor_difference += SL.match_length - res.length
|
|
112
116
|
SL.match_length = res.length
|
|
@@ -115,11 +119,11 @@ module SL
|
|
|
115
119
|
else
|
|
116
120
|
unless @links.key? @url
|
|
117
121
|
@highest_marker += 1
|
|
118
|
-
@links[@url] = format(
|
|
122
|
+
@links[@url] = format("%<pre>s%<m>04d", pre: @prefix, m: @highest_marker)
|
|
119
123
|
SL.add_footer SL.make_link(:ref_title, @links[@url], @url, title: title, force_title: false)
|
|
120
124
|
end
|
|
121
125
|
|
|
122
|
-
type = SL.config[
|
|
126
|
+
type = SL.config["inline"] ? :inline : :ref_link
|
|
123
127
|
res = SL.make_link(type, @link_text, @links[@url], title: false, force_title: false)
|
|
124
128
|
@cursor_difference += SL.match_length - res.length
|
|
125
129
|
SL.match_length = res.length
|
|
@@ -129,13 +133,13 @@ module SL
|
|
|
129
133
|
end
|
|
130
134
|
|
|
131
135
|
def custom_search(search_type, search_terms)
|
|
132
|
-
SL.config[
|
|
136
|
+
SL.config["custom_site_searches"].each do |k, v|
|
|
133
137
|
next unless search_type == k
|
|
134
138
|
|
|
135
|
-
@link_text = search_terms if !SL.titleize && @link_text ==
|
|
139
|
+
@link_text = search_terms if !SL.titleize && @link_text == ""
|
|
136
140
|
v = parse_arguments(v, { no_restore: true })
|
|
137
141
|
if v =~ %r{^(/|http)}i
|
|
138
|
-
search_type =
|
|
142
|
+
search_type = "r"
|
|
139
143
|
tokens = v.scan(/\$term\d+[ds]?/).sort.uniq
|
|
140
144
|
|
|
141
145
|
if !tokens.empty?
|
|
@@ -147,7 +151,7 @@ module SL
|
|
|
147
151
|
end
|
|
148
152
|
terms_p = search_terms.split(/ +/)
|
|
149
153
|
if terms_p.length > highest_token
|
|
150
|
-
remainder = terms_p[highest_token - 1..-1].join(
|
|
154
|
+
remainder = terms_p[highest_token - 1..-1].join(" ")
|
|
151
155
|
terms_p = terms_p[0..highest_token - 2]
|
|
152
156
|
terms_p.push(remainder)
|
|
153
157
|
end
|
|
@@ -159,12 +163,12 @@ module SL
|
|
|
159
163
|
case t
|
|
160
164
|
when /d$/
|
|
161
165
|
replacement.downcase!
|
|
162
|
-
re_down =
|
|
166
|
+
re_down = ""
|
|
163
167
|
when /s$/
|
|
164
168
|
replacement.slugify!
|
|
165
|
-
re_down =
|
|
169
|
+
re_down = ""
|
|
166
170
|
else
|
|
167
|
-
re_down =
|
|
171
|
+
re_down = "(?!d|s)"
|
|
168
172
|
end
|
|
169
173
|
v.gsub!(/#{Regexp.escape(t) + re_down}/, replacement.url_encode)
|
|
170
174
|
end
|
|
@@ -177,7 +181,7 @@ module SL
|
|
|
177
181
|
end
|
|
178
182
|
end
|
|
179
183
|
else
|
|
180
|
-
search_type = SL::GoogleSearch.api_key? ?
|
|
184
|
+
search_type = SL::GoogleSearch.api_key? ? "gg" : "g"
|
|
181
185
|
search_terms = "site:#{v} #{search_terms}"
|
|
182
186
|
end
|
|
183
187
|
|
|
@@ -195,7 +199,7 @@ module SL
|
|
|
195
199
|
|
|
196
200
|
parse_commands(input)
|
|
197
201
|
|
|
198
|
-
SL.config[
|
|
202
|
+
SL.config["inline"] = true if input.scan(/\]\(/).length == 1 && input.split(/\n/).length == 1
|
|
199
203
|
SL.errors = {}
|
|
200
204
|
SL.report = []
|
|
201
205
|
|
|
@@ -210,20 +214,20 @@ module SL
|
|
|
210
214
|
counter_links = 0
|
|
211
215
|
counter_errors = 0
|
|
212
216
|
|
|
213
|
-
input.sub!(/\n?<!-- Report:.*?-->\n?/m,
|
|
214
|
-
input.sub!(/\n?<!-- Errors:.*?-->\n?/m,
|
|
217
|
+
input.sub!(/\n?<!-- Report:.*?-->\n?/m, "")
|
|
218
|
+
input.sub!(/\n?<!-- Errors:.*?-->\n?/m, "")
|
|
215
219
|
|
|
216
220
|
input.scan(/\[(.*?)\]:\s+(.*?)\n/).each { |match| @links[match[1].strip] = match[0] }
|
|
217
221
|
|
|
218
|
-
@prefix = if SL.config[
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
222
|
+
@prefix = if SL.config["prefix_random"]
|
|
223
|
+
if input =~ /\[(\d{4}-)\d+\]: \S+/
|
|
224
|
+
Regexp.last_match(1)
|
|
225
|
+
else
|
|
226
|
+
format("%04d-", rand(9999))
|
|
227
|
+
end
|
|
228
|
+
else
|
|
229
|
+
""
|
|
230
|
+
end
|
|
227
231
|
|
|
228
232
|
@highest_marker = 0
|
|
229
233
|
input.scan(/^\s{,3}\[(?:#{@prefix})?(\d+)\]: /).each do
|
|
@@ -237,7 +241,7 @@ module SL
|
|
|
237
241
|
@footnote_counter = m[1].to_i if m[1].to_i > @footnote_counter
|
|
238
242
|
end
|
|
239
243
|
|
|
240
|
-
if SL.config[
|
|
244
|
+
if SL.config["complete_bare"]
|
|
241
245
|
rx = %r{(?ix-m)(?<!\(|:\s|<)(?:
|
|
242
246
|
(?:https?://)(?:[\da-z.-]+)\.(?:[a-z.]{2,6})
|
|
243
247
|
(?:[/\w\d.\-()_/+=?&%]*?(?=[\s\n]|$))
|
|
@@ -301,13 +305,13 @@ module SL
|
|
|
301
305
|
$stderr.print("\033[0K\rProcessed: #{counter_links} of #{total_links}, #{counter_errors} errors. ")
|
|
302
306
|
end
|
|
303
307
|
|
|
304
|
-
@link_text = this_match[1] ||
|
|
305
|
-
link_info = parse_arguments(this_match[2].strip).strip ||
|
|
308
|
+
@link_text = this_match[1] || ""
|
|
309
|
+
link_info = parse_arguments(this_match[2].strip).strip || ""
|
|
306
310
|
|
|
307
|
-
if @link_text.strip ==
|
|
311
|
+
if @link_text.strip == "" && link_info =~ /".*?"/
|
|
308
312
|
link_info.gsub!(/"(.*?)"/) do
|
|
309
313
|
m = Regexp.last_match
|
|
310
|
-
@link_text = m[1] if @link_text ==
|
|
314
|
+
@link_text = m[1] if @link_text == ""
|
|
311
315
|
m[0]
|
|
312
316
|
end
|
|
313
317
|
end
|
|
@@ -318,11 +322,11 @@ module SL
|
|
|
318
322
|
|
|
319
323
|
if link_info.strip =~ /:$/ && line.strip == match
|
|
320
324
|
@ref_title = true
|
|
321
|
-
link_info.sub!(/\s*:\s*$/,
|
|
325
|
+
link_info.sub!(/\s*:\s*$/, "")
|
|
322
326
|
end
|
|
323
327
|
|
|
324
|
-
unless !@link_text.empty? || !link_info.sub(/^[!\^]\S+/,
|
|
325
|
-
SL.add_error(
|
|
328
|
+
unless !@link_text.empty? || !link_info.sub(/^[!\^]\S+/, "").strip.empty?
|
|
329
|
+
SL.add_error("No input", match)
|
|
326
330
|
counter_errors += 1
|
|
327
331
|
invalid_search = true
|
|
328
332
|
end
|
|
@@ -340,43 +344,45 @@ module SL
|
|
|
340
344
|
elsif link_info =~ /^\^(.+)/
|
|
341
345
|
m = Regexp.last_match
|
|
342
346
|
create_footnote(m)
|
|
343
|
-
|
|
344
|
-
elsif (@link_text ==
|
|
347
|
+
# Handle [](URL) and [%](URL), filling in title
|
|
348
|
+
elsif (@link_text == "" || @link_text == "%") && SL::URL.url?(link_info)
|
|
345
349
|
add_title(link_info)
|
|
346
|
-
elsif (@link_text ==
|
|
347
|
-
SL.add_error(
|
|
350
|
+
elsif (@link_text == "" && link_info == "") || SL::URL.url?(link_info)
|
|
351
|
+
SL.add_error("Invalid search", match) unless SL::URL.url?(link_info)
|
|
348
352
|
match
|
|
349
353
|
else
|
|
350
|
-
link_info = @link_text if !@link_text.empty? && link_info ==
|
|
354
|
+
link_info = @link_text if !@link_text.empty? && link_info == ""
|
|
351
355
|
|
|
352
|
-
search_type =
|
|
353
|
-
search_terms =
|
|
356
|
+
search_type = ""
|
|
357
|
+
search_terms = ""
|
|
354
358
|
link_only = false
|
|
355
359
|
SL.clipboard = false
|
|
356
|
-
SL.titleize = SL.config[
|
|
360
|
+
SL.titleize = SL.config["empty_uses_page_title"]
|
|
357
361
|
|
|
358
362
|
if link_info =~ /^(?:[!\^](\S+))\s*(.*)$/
|
|
359
363
|
m = Regexp.last_match
|
|
360
364
|
|
|
361
365
|
search_type = if m[1].nil?
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
+
SL::GoogleSearch.api_key? ? "gg" : "g"
|
|
367
|
+
else
|
|
368
|
+
m[1]
|
|
369
|
+
end
|
|
366
370
|
|
|
367
|
-
search_terms = m[2].gsub(/(^["']|["']$)/,
|
|
371
|
+
search_terms = m[2].gsub(/(^["']|["']$)/, "")
|
|
368
372
|
search_terms.strip!
|
|
369
373
|
|
|
370
374
|
# if the link text is just '%' replace with title regardless of config settings
|
|
371
|
-
if @link_text ==
|
|
375
|
+
if @link_text == "%" && search_terms && !search_terms.empty?
|
|
372
376
|
SL.titleize = true
|
|
373
|
-
@link_text =
|
|
377
|
+
@link_text = ""
|
|
374
378
|
end
|
|
375
379
|
|
|
376
|
-
search_terms = @link_text if search_terms ==
|
|
380
|
+
search_terms = @link_text if search_terms == ""
|
|
377
381
|
|
|
378
382
|
# if the input starts with a +, append it to the link text as the search terms
|
|
379
|
-
|
|
383
|
+
if search_terms.strip =~ /^\+[^+]/
|
|
384
|
+
search_terms = "#{@link_text} #{search_terms.strip.sub(/^\+\s*/, "")}"
|
|
385
|
+
end
|
|
380
386
|
|
|
381
387
|
# if the end of input contain "^", copy to clipboard instead of STDOUT
|
|
382
388
|
SL.clipboard = true if search_terms =~ /(!!)?\^(!!)?$/
|
|
@@ -384,8 +390,7 @@ module SL
|
|
|
384
390
|
# if the end of input contains "!!", only print the url
|
|
385
391
|
link_only = true if search_terms =~ /!!\^?$/
|
|
386
392
|
|
|
387
|
-
search_terms.sub
|
|
388
|
-
|
|
393
|
+
search_terms = search_terms.sub(/(!!)?\^?(!!)?$/, "")
|
|
389
394
|
elsif link_info =~ /^!/
|
|
390
395
|
search_word = link_info.match(/^!(\S+)/)
|
|
391
396
|
|
|
@@ -393,7 +398,7 @@ module SL
|
|
|
393
398
|
search_type = search_word[1] unless search_word.nil?
|
|
394
399
|
search_terms = @link_text
|
|
395
400
|
elsif search_word && search_word[1] =~ /^(\S+\.)+\S+$/
|
|
396
|
-
search_type = SL::GoogleSearch.api_key? ?
|
|
401
|
+
search_type = SL::GoogleSearch.api_key? ? "gg" : "g"
|
|
397
402
|
puts SL::GoogleSearch.api_key?
|
|
398
403
|
search_terms = "site:#{search_word[1]} #{@link_text}"
|
|
399
404
|
else
|
|
@@ -402,13 +407,13 @@ module SL
|
|
|
402
407
|
search_terms = false
|
|
403
408
|
end
|
|
404
409
|
elsif @link_text && !@link_text.empty? && (!link_info || link_info.empty?)
|
|
405
|
-
search_type = SL::GoogleSearch.api_key? ?
|
|
410
|
+
search_type = SL::GoogleSearch.api_key? ? "gg" : "g"
|
|
406
411
|
search_terms = @link_text
|
|
407
412
|
elsif link_info && !link_info.empty?
|
|
408
|
-
search_type = SL::GoogleSearch.api_key? ?
|
|
413
|
+
search_type = SL::GoogleSearch.api_key? ? "gg" : "g"
|
|
409
414
|
search_terms = link_info
|
|
410
415
|
else
|
|
411
|
-
SL.add_error(
|
|
416
|
+
SL.add_error("Invalid search", match)
|
|
412
417
|
search_type = false
|
|
413
418
|
search_terms = false
|
|
414
419
|
end
|
|
@@ -424,7 +429,7 @@ module SL
|
|
|
424
429
|
@url, title, @link_text = do_search(search_type, search_terms, @link_text, @search_count)
|
|
425
430
|
end
|
|
426
431
|
|
|
427
|
-
if (@link_text ==
|
|
432
|
+
if (@link_text == "" || @link_text == "%") && @url
|
|
428
433
|
if title
|
|
429
434
|
@link_text = title
|
|
430
435
|
else
|
|
@@ -433,13 +438,13 @@ module SL
|
|
|
433
438
|
end
|
|
434
439
|
|
|
435
440
|
if @url
|
|
436
|
-
title = SL::URL.title(@url) if SL.titleize && title ==
|
|
441
|
+
title = SL::URL.title(@url) if SL.titleize && title == ""
|
|
437
442
|
|
|
438
|
-
@link_text = title if @link_text ==
|
|
443
|
+
@link_text = title if @link_text == "" && title
|
|
439
444
|
force_title = search_type =~ /def/ ? true : false
|
|
440
445
|
|
|
441
|
-
if link_only || search_type =~ /sp(ell)?/ || @url ==
|
|
442
|
-
@url = title if @url ==
|
|
446
|
+
if link_only || search_type =~ /sp(ell)?/ || @url == "embed"
|
|
447
|
+
@url = title if @url == "embed"
|
|
443
448
|
@cursor_difference += SL.match_length - @url.length
|
|
444
449
|
SL.match_length = @url.length
|
|
445
450
|
SL.add_report("#{@match_string} => #{@url}")
|
|
@@ -450,7 +455,7 @@ module SL
|
|
|
450
455
|
SL.add_footer SL.make_link(:ref_title, @link_text, @url, title: title, force_title: force_title)
|
|
451
456
|
end
|
|
452
457
|
@delete_line = true
|
|
453
|
-
elsif SL.config[
|
|
458
|
+
elsif SL.config["inline"]
|
|
454
459
|
res = SL.make_link(:inline, @link_text, @url, title: title, force_title: force_title)
|
|
455
460
|
@cursor_difference += SL.match_length - res.length
|
|
456
461
|
SL.match_length = res.length
|
|
@@ -459,11 +464,11 @@ module SL
|
|
|
459
464
|
else
|
|
460
465
|
unless @links.key? @url
|
|
461
466
|
@highest_marker += 1
|
|
462
|
-
@links[@url] = format(
|
|
467
|
+
@links[@url] = format("%<pre>s%<m>04d", pre: @prefix, m: @highest_marker)
|
|
463
468
|
SL.add_footer SL.make_link(:ref_title, @links[@url], @url, title: title, force_title: force_title)
|
|
464
469
|
end
|
|
465
470
|
|
|
466
|
-
type = SL.config[
|
|
471
|
+
type = SL.config["inline"] ? :inline : :ref_link
|
|
467
472
|
res = SL.make_link(type, @link_text, @links[@url], title: false, force_title: force_title)
|
|
468
473
|
@cursor_difference += SL.match_length - res.length
|
|
469
474
|
SL.match_length = res.length
|
|
@@ -471,12 +476,12 @@ module SL
|
|
|
471
476
|
res
|
|
472
477
|
end
|
|
473
478
|
else
|
|
474
|
-
SL.add_error(
|
|
479
|
+
SL.add_error("No results", "#{search_terms} (#{@match_string})")
|
|
475
480
|
counter_errors += 1
|
|
476
481
|
match
|
|
477
482
|
end
|
|
478
483
|
else
|
|
479
|
-
SL.add_error(
|
|
484
|
+
SL.add_error("Invalid search", match)
|
|
480
485
|
counter_errors += 1
|
|
481
486
|
match
|
|
482
487
|
end
|
|
@@ -490,7 +495,7 @@ module SL
|
|
|
490
495
|
|
|
491
496
|
input = out.delete_if { |l| l.strip =~ /^<!--DELETE-->$/ }.join("\n")
|
|
492
497
|
|
|
493
|
-
if SL.config[
|
|
498
|
+
if SL.config["inline"]
|
|
494
499
|
SL.add_output "#{input}\n"
|
|
495
500
|
SL.add_output "\n#{SL.print_footer}" unless SL.footer.empty?
|
|
496
501
|
elsif SL.footer.empty?
|
|
@@ -529,7 +534,7 @@ module SL
|
|
|
529
534
|
|
|
530
535
|
# if end of input contains ~, pull url from clipboard
|
|
531
536
|
if input =~ /~[:\^!\s]*$/
|
|
532
|
-
input.sub!(/[:!\^\s~]*$/,
|
|
537
|
+
input.sub!(/[:!\^\s~]*$/, "")
|
|
533
538
|
clipboard = `__CF_USER_TEXT_ENCODING=$UID:0x8000100:0x8000100 pbpaste`.strip
|
|
534
539
|
if SL::URL.url?(clipboard)
|
|
535
540
|
type = reference_link ? :ref_title : :inline
|
|
@@ -540,7 +545,7 @@ module SL
|
|
|
540
545
|
Process.exit
|
|
541
546
|
end
|
|
542
547
|
|
|
543
|
-
input.sub!(/[:!\^\s~]*$/,
|
|
548
|
+
input.sub!(/[:!\^\s~]*$/, "")
|
|
544
549
|
|
|
545
550
|
## Maybe if input is just a URL, convert it to a link
|
|
546
551
|
## using hostname as text without doing search
|
|
@@ -552,10 +557,10 @@ module SL
|
|
|
552
557
|
end
|
|
553
558
|
|
|
554
559
|
# check for additional search terms in parenthesis
|
|
555
|
-
additional_terms =
|
|
560
|
+
additional_terms = ""
|
|
556
561
|
if input =~ /\((.*?)\)/
|
|
557
562
|
additional_terms = " #{Regexp.last_match(1).strip}"
|
|
558
|
-
input.sub!(/\(.*?\)/,
|
|
563
|
+
input.sub!(/\(.*?\)/, "")
|
|
559
564
|
end
|
|
560
565
|
|
|
561
566
|
# Maybe detect "search + addition terms" and remove additional terms from link text?
|
|
@@ -585,13 +590,13 @@ module SL
|
|
|
585
590
|
if SL::Searches.valid_search?(type) || type =~ /^(\S+\.)+\S+$/
|
|
586
591
|
if type && terms && !terms.empty?
|
|
587
592
|
# Iterate through custom searches for a match, perform search if matched
|
|
588
|
-
SL.config[
|
|
593
|
+
SL.config["custom_site_searches"].each do |k, v|
|
|
589
594
|
next unless type == k
|
|
590
595
|
|
|
591
|
-
@link_text = terms if @link_text ==
|
|
596
|
+
@link_text = terms if @link_text == ""
|
|
592
597
|
v = parse_arguments(v, { no_restore: true })
|
|
593
598
|
if v =~ %r{^(/|http)}i
|
|
594
|
-
type =
|
|
599
|
+
type = "r"
|
|
595
600
|
tokens = v.scan(/\$term\d+[ds]?/).sort.uniq
|
|
596
601
|
|
|
597
602
|
if !tokens.empty?
|
|
@@ -602,7 +607,7 @@ module SL
|
|
|
602
607
|
end
|
|
603
608
|
terms_p = terms.split(/ +/)
|
|
604
609
|
if terms_p.length > highest_token
|
|
605
|
-
remainder = terms_p[highest_token - 1..-1].join(
|
|
610
|
+
remainder = terms_p[highest_token - 1..-1].join(" ")
|
|
606
611
|
terms_p = terms_p[0..highest_token - 2]
|
|
607
612
|
terms_p.push(remainder)
|
|
608
613
|
end
|
|
@@ -613,15 +618,15 @@ module SL
|
|
|
613
618
|
replacement = terms_p[int]
|
|
614
619
|
|
|
615
620
|
re_down = case t
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
621
|
+
when /d$/
|
|
622
|
+
replacement.downcase!
|
|
623
|
+
""
|
|
624
|
+
when /s$/
|
|
625
|
+
replacement.slugify!
|
|
626
|
+
""
|
|
627
|
+
else
|
|
628
|
+
"(?!d|s)"
|
|
629
|
+
end
|
|
625
630
|
v.gsub!(/#{Regexp.escape(t) + re_down}/, replacement.url_encode)
|
|
626
631
|
end
|
|
627
632
|
terms = v
|
|
@@ -633,7 +638,7 @@ module SL
|
|
|
633
638
|
end
|
|
634
639
|
end
|
|
635
640
|
else
|
|
636
|
-
type = SL::GoogleSearch.api_key? ?
|
|
641
|
+
type = SL::GoogleSearch.api_key? ? "gg" : "g"
|
|
637
642
|
terms = "site:#{v} #{terms}"
|
|
638
643
|
end
|
|
639
644
|
|
|
@@ -644,7 +649,7 @@ module SL
|
|
|
644
649
|
# if contains TLD, use site-specific search
|
|
645
650
|
if type =~ /^(\S+\.)+\S+$/
|
|
646
651
|
terms = "site:#{type} #{terms}"
|
|
647
|
-
type = SL::GoogleSearch.api_key? ?
|
|
652
|
+
type = SL::GoogleSearch.api_key? ? "gg" : "g"
|
|
648
653
|
end
|
|
649
654
|
@search_count ||= 0
|
|
650
655
|
@search_count += 1
|
|
@@ -654,15 +659,15 @@ module SL
|
|
|
654
659
|
SL.add_error("Invalid search#{SL::Searches.did_you_mean(type)}", input)
|
|
655
660
|
counter_errors += 1
|
|
656
661
|
end
|
|
657
|
-
|
|
662
|
+
# Social handle expansion
|
|
658
663
|
when /^([tfilm])?@(\S+)\s*$/
|
|
659
664
|
type = Regexp.last_match(1)
|
|
660
665
|
type ||= if Regexp.last_match(2) =~ /[a-z0-9_]@[a-z0-9_.]+/i
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
@link_text = input.sub(/^[tfilm]/,
|
|
666
|
+
"m"
|
|
667
|
+
else
|
|
668
|
+
"t"
|
|
669
|
+
end
|
|
670
|
+
@link_text = input.sub(/^[tfilm]/, "")
|
|
666
671
|
@url, title = SL::SocialSearch.social_handle(type, @link_text)
|
|
667
672
|
@link_text = title
|
|
668
673
|
else
|
|
@@ -675,7 +680,7 @@ module SL
|
|
|
675
680
|
SL.add_output(@url)
|
|
676
681
|
elsif link_only
|
|
677
682
|
SL.add_output(@url)
|
|
678
|
-
elsif @url ==
|
|
683
|
+
elsif @url == "embed"
|
|
679
684
|
SL.add_output(title)
|
|
680
685
|
else
|
|
681
686
|
type = reference_link ? :ref_title : :inline
|
|
@@ -684,17 +689,17 @@ module SL
|
|
|
684
689
|
SL.print_errors
|
|
685
690
|
end
|
|
686
691
|
else
|
|
687
|
-
SL.add_error(
|
|
692
|
+
SL.add_error("No results", title)
|
|
688
693
|
SL.add_output SL.originput.chomp
|
|
689
694
|
SL.print_errors
|
|
690
695
|
end
|
|
691
696
|
|
|
692
697
|
if SL.clipboard
|
|
693
698
|
if SL.output == SL.originput
|
|
694
|
-
warn
|
|
699
|
+
warn "No results found"
|
|
695
700
|
else
|
|
696
|
-
`echo #{Shellwords.escape(SL.output.join(
|
|
697
|
-
warn
|
|
701
|
+
`echo #{Shellwords.escape(SL.output.join(""))}|tr -d "\n"|pbcopy`
|
|
702
|
+
warn "Results in clipboard"
|
|
698
703
|
end
|
|
699
704
|
end
|
|
700
705
|
end
|
data/lib/searchlink/plist.rb
CHANGED
|
@@ -64,11 +64,11 @@ module Plist
|
|
|
64
64
|
COMMENT_END = /.*?-->/um.freeze
|
|
65
65
|
|
|
66
66
|
def parse
|
|
67
|
-
plist_tags = PTag.mappings.keys.join(
|
|
67
|
+
plist_tags = PTag.mappings.keys.join("|")
|
|
68
68
|
start_tag = /<(#{plist_tags})([^>]*)>/i
|
|
69
69
|
end_tag = %r{</(#{plist_tags})[^>]*>}i
|
|
70
70
|
|
|
71
|
-
require
|
|
71
|
+
require "strscan"
|
|
72
72
|
|
|
73
73
|
@scanner = StringScanner.new(@xml)
|
|
74
74
|
until @scanner.eos?
|
|
@@ -84,7 +84,7 @@ module Plist
|
|
|
84
84
|
elsif @scanner.scan(end_tag)
|
|
85
85
|
@listener.tag_end(@scanner[1])
|
|
86
86
|
else
|
|
87
|
-
raise
|
|
87
|
+
raise "Unimplemented element"
|
|
88
88
|
end
|
|
89
89
|
end
|
|
90
90
|
end
|
|
@@ -98,8 +98,8 @@ module Plist
|
|
|
98
98
|
|
|
99
99
|
def self.inherited(sub_class)
|
|
100
100
|
key = sub_class.to_s.downcase
|
|
101
|
-
key.gsub!(/^plist::/,
|
|
102
|
-
key.gsub!(/^p/,
|
|
101
|
+
key.gsub!(/^plist::/, "")
|
|
102
|
+
key.gsub!(/^p/, "") unless key == "plist"
|
|
103
103
|
|
|
104
104
|
@@mappings[key] = sub_class
|
|
105
105
|
end
|
|
@@ -110,7 +110,7 @@ module Plist
|
|
|
110
110
|
end
|
|
111
111
|
|
|
112
112
|
def to_ruby
|
|
113
|
-
raise
|
|
113
|
+
raise "Unimplemented: " + self.class.to_s + "#to_ruby on #{inspect}"
|
|
114
114
|
end
|
|
115
115
|
end
|
|
116
116
|
|
|
@@ -140,13 +140,13 @@ module Plist
|
|
|
140
140
|
|
|
141
141
|
class PKey < PTag
|
|
142
142
|
def to_ruby
|
|
143
|
-
CGI.unescapeHTML(text ||
|
|
143
|
+
CGI.unescapeHTML(text || "")
|
|
144
144
|
end
|
|
145
145
|
end
|
|
146
146
|
|
|
147
147
|
class PString < PTag
|
|
148
148
|
def to_ruby
|
|
149
|
-
CGI.unescapeHTML(text ||
|
|
149
|
+
CGI.unescapeHTML(text || "")
|
|
150
150
|
end
|
|
151
151
|
end
|
|
152
152
|
|
|
@@ -180,17 +180,17 @@ module Plist
|
|
|
180
180
|
end
|
|
181
181
|
end
|
|
182
182
|
|
|
183
|
-
require
|
|
183
|
+
require "date"
|
|
184
184
|
class PDate < PTag
|
|
185
185
|
def to_ruby
|
|
186
186
|
DateTime.parse(text)
|
|
187
187
|
end
|
|
188
188
|
end
|
|
189
189
|
|
|
190
|
-
require
|
|
190
|
+
require "base64"
|
|
191
191
|
class PData < PTag
|
|
192
192
|
def to_ruby
|
|
193
|
-
data = Base64.decode64(text.gsub(/\s+/,
|
|
193
|
+
data = Base64.decode64(text.gsub(/\s+/, ""))
|
|
194
194
|
|
|
195
195
|
begin
|
|
196
196
|
Marshal.load(data)
|