searchlink 2.3.74 → 2.3.77
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 +116 -113
- 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
|
-
|
|
325
|
-
SL.add_error(
|
|
328
|
+
if @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,8 +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? ?
|
|
397
|
-
puts SL::GoogleSearch.api_key?
|
|
401
|
+
search_type = SL::GoogleSearch.api_key? ? "gg" : "g"
|
|
398
402
|
search_terms = "site:#{search_word[1]} #{@link_text}"
|
|
399
403
|
else
|
|
400
404
|
SL.add_error("Invalid search#{SL::Searches.did_you_mean(search_word[1])}", match)
|
|
@@ -402,13 +406,13 @@ module SL
|
|
|
402
406
|
search_terms = false
|
|
403
407
|
end
|
|
404
408
|
elsif @link_text && !@link_text.empty? && (!link_info || link_info.empty?)
|
|
405
|
-
search_type = SL::GoogleSearch.api_key? ?
|
|
409
|
+
search_type = SL::GoogleSearch.api_key? ? "gg" : "g"
|
|
406
410
|
search_terms = @link_text
|
|
407
411
|
elsif link_info && !link_info.empty?
|
|
408
|
-
search_type = SL::GoogleSearch.api_key? ?
|
|
412
|
+
search_type = SL::GoogleSearch.api_key? ? "gg" : "g"
|
|
409
413
|
search_terms = link_info
|
|
410
414
|
else
|
|
411
|
-
SL.add_error(
|
|
415
|
+
SL.add_error("Invalid search", match)
|
|
412
416
|
search_type = false
|
|
413
417
|
search_terms = false
|
|
414
418
|
end
|
|
@@ -419,12 +423,11 @@ module SL
|
|
|
419
423
|
|
|
420
424
|
if (search_type && search_terms) || @url
|
|
421
425
|
# warn "Searching #{search_type} for #{search_terms}"
|
|
422
|
-
unless @url
|
|
423
|
-
@search_count += 1
|
|
424
|
-
@url, title, @link_text = do_search(search_type, search_terms, @link_text, @search_count)
|
|
425
|
-
end
|
|
426
426
|
|
|
427
|
-
|
|
427
|
+
@search_count += 1
|
|
428
|
+
@url, title, @link_text = do_search(search_type, search_terms, @link_text, @search_count)
|
|
429
|
+
|
|
430
|
+
if (@link_text == "" || @link_text == "%") && @url
|
|
428
431
|
if title
|
|
429
432
|
@link_text = title
|
|
430
433
|
else
|
|
@@ -433,13 +436,13 @@ module SL
|
|
|
433
436
|
end
|
|
434
437
|
|
|
435
438
|
if @url
|
|
436
|
-
title = SL::URL.title(@url) if SL.titleize && title ==
|
|
439
|
+
title = SL::URL.title(@url) if SL.titleize && title == ""
|
|
437
440
|
|
|
438
|
-
@link_text = title if @link_text ==
|
|
441
|
+
@link_text = title if @link_text == "" && title
|
|
439
442
|
force_title = search_type =~ /def/ ? true : false
|
|
440
443
|
|
|
441
|
-
if link_only || search_type =~ /sp(ell)?/ || @url ==
|
|
442
|
-
@url = title if @url ==
|
|
444
|
+
if link_only || search_type =~ /sp(ell)?/ || @url == "embed"
|
|
445
|
+
@url = title if @url == "embed"
|
|
443
446
|
@cursor_difference += SL.match_length - @url.length
|
|
444
447
|
SL.match_length = @url.length
|
|
445
448
|
SL.add_report("#{@match_string} => #{@url}")
|
|
@@ -450,7 +453,7 @@ module SL
|
|
|
450
453
|
SL.add_footer SL.make_link(:ref_title, @link_text, @url, title: title, force_title: force_title)
|
|
451
454
|
end
|
|
452
455
|
@delete_line = true
|
|
453
|
-
elsif SL.config[
|
|
456
|
+
elsif SL.config["inline"]
|
|
454
457
|
res = SL.make_link(:inline, @link_text, @url, title: title, force_title: force_title)
|
|
455
458
|
@cursor_difference += SL.match_length - res.length
|
|
456
459
|
SL.match_length = res.length
|
|
@@ -459,11 +462,11 @@ module SL
|
|
|
459
462
|
else
|
|
460
463
|
unless @links.key? @url
|
|
461
464
|
@highest_marker += 1
|
|
462
|
-
@links[@url] = format(
|
|
465
|
+
@links[@url] = format("%<pre>s%<m>04d", pre: @prefix, m: @highest_marker)
|
|
463
466
|
SL.add_footer SL.make_link(:ref_title, @links[@url], @url, title: title, force_title: force_title)
|
|
464
467
|
end
|
|
465
468
|
|
|
466
|
-
type = SL.config[
|
|
469
|
+
type = SL.config["inline"] ? :inline : :ref_link
|
|
467
470
|
res = SL.make_link(type, @link_text, @links[@url], title: false, force_title: force_title)
|
|
468
471
|
@cursor_difference += SL.match_length - res.length
|
|
469
472
|
SL.match_length = res.length
|
|
@@ -471,12 +474,12 @@ module SL
|
|
|
471
474
|
res
|
|
472
475
|
end
|
|
473
476
|
else
|
|
474
|
-
SL.add_error(
|
|
477
|
+
SL.add_error("No results", "#{search_terms} (#{@match_string})")
|
|
475
478
|
counter_errors += 1
|
|
476
479
|
match
|
|
477
480
|
end
|
|
478
481
|
else
|
|
479
|
-
SL.add_error(
|
|
482
|
+
SL.add_error("Invalid search", match)
|
|
480
483
|
counter_errors += 1
|
|
481
484
|
match
|
|
482
485
|
end
|
|
@@ -490,7 +493,7 @@ module SL
|
|
|
490
493
|
|
|
491
494
|
input = out.delete_if { |l| l.strip =~ /^<!--DELETE-->$/ }.join("\n")
|
|
492
495
|
|
|
493
|
-
if SL.config[
|
|
496
|
+
if SL.config["inline"]
|
|
494
497
|
SL.add_output "#{input}\n"
|
|
495
498
|
SL.add_output "\n#{SL.print_footer}" unless SL.footer.empty?
|
|
496
499
|
elsif SL.footer.empty?
|
|
@@ -529,7 +532,7 @@ module SL
|
|
|
529
532
|
|
|
530
533
|
# if end of input contains ~, pull url from clipboard
|
|
531
534
|
if input =~ /~[:\^!\s]*$/
|
|
532
|
-
input.sub!(/[:!\^\s~]*$/,
|
|
535
|
+
input.sub!(/[:!\^\s~]*$/, "")
|
|
533
536
|
clipboard = `__CF_USER_TEXT_ENCODING=$UID:0x8000100:0x8000100 pbpaste`.strip
|
|
534
537
|
if SL::URL.url?(clipboard)
|
|
535
538
|
type = reference_link ? :ref_title : :inline
|
|
@@ -540,7 +543,7 @@ module SL
|
|
|
540
543
|
Process.exit
|
|
541
544
|
end
|
|
542
545
|
|
|
543
|
-
input.sub!(/[:!\^\s~]*$/,
|
|
546
|
+
input.sub!(/[:!\^\s~]*$/, "")
|
|
544
547
|
|
|
545
548
|
## Maybe if input is just a URL, convert it to a link
|
|
546
549
|
## using hostname as text without doing search
|
|
@@ -552,10 +555,10 @@ module SL
|
|
|
552
555
|
end
|
|
553
556
|
|
|
554
557
|
# check for additional search terms in parenthesis
|
|
555
|
-
additional_terms =
|
|
558
|
+
additional_terms = ""
|
|
556
559
|
if input =~ /\((.*?)\)/
|
|
557
560
|
additional_terms = " #{Regexp.last_match(1).strip}"
|
|
558
|
-
input.sub!(/\(.*?\)/,
|
|
561
|
+
input.sub!(/\(.*?\)/, "")
|
|
559
562
|
end
|
|
560
563
|
|
|
561
564
|
# Maybe detect "search + addition terms" and remove additional terms from link text?
|
|
@@ -585,13 +588,13 @@ module SL
|
|
|
585
588
|
if SL::Searches.valid_search?(type) || type =~ /^(\S+\.)+\S+$/
|
|
586
589
|
if type && terms && !terms.empty?
|
|
587
590
|
# Iterate through custom searches for a match, perform search if matched
|
|
588
|
-
SL.config[
|
|
591
|
+
SL.config["custom_site_searches"].each do |k, v|
|
|
589
592
|
next unless type == k
|
|
590
593
|
|
|
591
|
-
@link_text = terms if @link_text ==
|
|
594
|
+
@link_text = terms if @link_text == ""
|
|
592
595
|
v = parse_arguments(v, { no_restore: true })
|
|
593
596
|
if v =~ %r{^(/|http)}i
|
|
594
|
-
type =
|
|
597
|
+
type = "r"
|
|
595
598
|
tokens = v.scan(/\$term\d+[ds]?/).sort.uniq
|
|
596
599
|
|
|
597
600
|
if !tokens.empty?
|
|
@@ -602,7 +605,7 @@ module SL
|
|
|
602
605
|
end
|
|
603
606
|
terms_p = terms.split(/ +/)
|
|
604
607
|
if terms_p.length > highest_token
|
|
605
|
-
remainder = terms_p[highest_token - 1..-1].join(
|
|
608
|
+
remainder = terms_p[highest_token - 1..-1].join(" ")
|
|
606
609
|
terms_p = terms_p[0..highest_token - 2]
|
|
607
610
|
terms_p.push(remainder)
|
|
608
611
|
end
|
|
@@ -613,15 +616,15 @@ module SL
|
|
|
613
616
|
replacement = terms_p[int]
|
|
614
617
|
|
|
615
618
|
re_down = case t
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
619
|
+
when /d$/
|
|
620
|
+
replacement.downcase!
|
|
621
|
+
""
|
|
622
|
+
when /s$/
|
|
623
|
+
replacement.slugify!
|
|
624
|
+
""
|
|
625
|
+
else
|
|
626
|
+
"(?!d|s)"
|
|
627
|
+
end
|
|
625
628
|
v.gsub!(/#{Regexp.escape(t) + re_down}/, replacement.url_encode)
|
|
626
629
|
end
|
|
627
630
|
terms = v
|
|
@@ -633,7 +636,7 @@ module SL
|
|
|
633
636
|
end
|
|
634
637
|
end
|
|
635
638
|
else
|
|
636
|
-
type = SL::GoogleSearch.api_key? ?
|
|
639
|
+
type = SL::GoogleSearch.api_key? ? "gg" : "g"
|
|
637
640
|
terms = "site:#{v} #{terms}"
|
|
638
641
|
end
|
|
639
642
|
|
|
@@ -644,7 +647,7 @@ module SL
|
|
|
644
647
|
# if contains TLD, use site-specific search
|
|
645
648
|
if type =~ /^(\S+\.)+\S+$/
|
|
646
649
|
terms = "site:#{type} #{terms}"
|
|
647
|
-
type = SL::GoogleSearch.api_key? ?
|
|
650
|
+
type = SL::GoogleSearch.api_key? ? "gg" : "g"
|
|
648
651
|
end
|
|
649
652
|
@search_count ||= 0
|
|
650
653
|
@search_count += 1
|
|
@@ -654,15 +657,15 @@ module SL
|
|
|
654
657
|
SL.add_error("Invalid search#{SL::Searches.did_you_mean(type)}", input)
|
|
655
658
|
counter_errors += 1
|
|
656
659
|
end
|
|
657
|
-
|
|
660
|
+
# Social handle expansion
|
|
658
661
|
when /^([tfilm])?@(\S+)\s*$/
|
|
659
662
|
type = Regexp.last_match(1)
|
|
660
663
|
type ||= if Regexp.last_match(2) =~ /[a-z0-9_]@[a-z0-9_.]+/i
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
@link_text = input.sub(/^[tfilm]/,
|
|
664
|
+
"m"
|
|
665
|
+
else
|
|
666
|
+
"t"
|
|
667
|
+
end
|
|
668
|
+
@link_text = input.sub(/^[tfilm]/, "")
|
|
666
669
|
@url, title = SL::SocialSearch.social_handle(type, @link_text)
|
|
667
670
|
@link_text = title
|
|
668
671
|
else
|
|
@@ -675,7 +678,7 @@ module SL
|
|
|
675
678
|
SL.add_output(@url)
|
|
676
679
|
elsif link_only
|
|
677
680
|
SL.add_output(@url)
|
|
678
|
-
elsif @url ==
|
|
681
|
+
elsif @url == "embed"
|
|
679
682
|
SL.add_output(title)
|
|
680
683
|
else
|
|
681
684
|
type = reference_link ? :ref_title : :inline
|
|
@@ -684,17 +687,17 @@ module SL
|
|
|
684
687
|
SL.print_errors
|
|
685
688
|
end
|
|
686
689
|
else
|
|
687
|
-
SL.add_error(
|
|
690
|
+
SL.add_error("No results", title)
|
|
688
691
|
SL.add_output SL.originput.chomp
|
|
689
692
|
SL.print_errors
|
|
690
693
|
end
|
|
691
694
|
|
|
692
695
|
if SL.clipboard
|
|
693
696
|
if SL.output == SL.originput
|
|
694
|
-
warn
|
|
697
|
+
warn "No results found"
|
|
695
698
|
else
|
|
696
|
-
`echo #{Shellwords.escape(SL.output.join(
|
|
697
|
-
warn
|
|
699
|
+
`echo #{Shellwords.escape(SL.output.join(""))}|tr -d "\n"|pbcopy`
|
|
700
|
+
warn "Results in clipboard"
|
|
698
701
|
end
|
|
699
702
|
end
|
|
700
703
|
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)
|