searchlink 2.3.80 → 2.3.82
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 +102 -45
- data/lib/searchlink/curl/html.rb +1 -1
- data/lib/searchlink/curl/json.rb +1 -1
- data/lib/searchlink/parse.rb +27 -4
- data/lib/searchlink/plist.rb +91 -88
- data/lib/searchlink/searches/amazon.rb +8 -0
- data/lib/searchlink/searches/bitly.rb +13 -0
- data/lib/searchlink/searches/duckduckgo.rb +2 -0
- data/lib/searchlink/searches/github.rb +9 -1
- data/lib/searchlink/searches/google.rb +10 -0
- data/lib/searchlink/searches/history.rb +26 -0
- data/lib/searchlink/searches/isgd.rb +3 -3
- data/lib/searchlink/searches/itunes.rb +8 -1
- data/lib/searchlink/searches/lyrics.rb +19 -0
- data/lib/searchlink/searches/pinboard.rb +12 -5
- data/lib/searchlink/searches/social.rb +9 -0
- data/lib/searchlink/searches/youtube.rb +2 -2
- data/lib/searchlink/searches.rb +6 -5
- data/lib/searchlink/string.rb +29 -7
- data/lib/searchlink/tokens.rb +5 -0
- data/lib/searchlink/url.rb +27 -1
- data/lib/searchlink/version.rb +6 -2
- metadata +18 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 499667c8dd4020230af00d6a9a989382fbddaca1acb785ddd32cd0ab66035269
|
4
|
+
data.tar.gz: b2fe70d89c47cb5e14a591c5354212f2e97736f87ae95dcdd27d84706109850b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39c83199e303d8a2e258096c5f9a0182dbea1fd2ffbe485c9d6e89eec1d98cd4e282d87669278854d44a4daa5514bd31c85b6fd9ad9865524581152d9efd78c3
|
7
|
+
data.tar.gz: 459bee4c106e470de91b6644a4a690ad3296bdc7e5c59de6678fe2f3e4fd5f02f1795efd191d0e91e201c4449e7a063f636deaa6e594f59a4219ba8aeee8c651
|
data/lib/searchlink/config.rb
CHANGED
@@ -32,7 +32,9 @@ module SL
|
|
32
32
|
|
33
33
|
def initialize(opt = {})
|
34
34
|
SL.printout = opt[:echo] || false
|
35
|
-
|
35
|
+
if File.exist? config_file
|
36
|
+
write_new_plugin_config
|
37
|
+
else
|
36
38
|
default_config = <<~ENDCONFIG
|
37
39
|
# set to true to have an HTML comment included detailing any errors
|
38
40
|
# Can be disabled per search with `--d`, or enabled with `++d`.
|
@@ -80,22 +82,6 @@ module SL
|
|
80
82
|
# E.g. [](!g Search Text)
|
81
83
|
empty_uses_page_title: false
|
82
84
|
|
83
|
-
# Formatting for social links, use %service%, %user%, and %url%
|
84
|
-
# E.g. "%user% on %service%" => "ttscoff on Twitter"
|
85
|
-
# "%service%/%user%" => "Twitter/ttscoff"
|
86
|
-
# "%url%" => "twitter.com/ttscoff"
|
87
|
-
social_template: "%service%/%user%"
|
88
|
-
|
89
|
-
# append affiliate link info to iTunes urls, empty quotes for none
|
90
|
-
# example:
|
91
|
-
# itunes_affiliate: "&at=10l4tL&ct=searchlink"
|
92
|
-
itunes_affiliate: "&at=10l4tL&ct=searchlink"
|
93
|
-
|
94
|
-
# to create Amazon affiliate links, set amazon_partner to your amazon
|
95
|
-
# affiliate tag
|
96
|
-
# amazon_partner: "bretttercom-20"
|
97
|
-
amazon_partner: "bretttercom-20"
|
98
|
-
|
99
85
|
# To create custom abbreviations for Google Site Searches,
|
100
86
|
# add to (or replace) the hash below.
|
101
87
|
# "abbreviation" => "site.url",
|
@@ -129,35 +115,14 @@ module SL
|
|
129
115
|
dev: developer.apple.com
|
130
116
|
nq: http://nerdquery.com/?media_only=0&query=$term&search=1&category=-1&catid=&type=and&results=50&db=0&prefix=0
|
131
117
|
gs: http://scholar.google.com/scholar?btnI&hl=en&q=$term&btnG=&as_sdt=80006
|
132
|
-
# Remove or comment (with #) history searches you don't want
|
133
|
-
# performed by `!h`. You can force-enable them per search, e.g.
|
134
|
-
# `!hsh` (Safari History only), `!hcb` (Chrome Bookmarks only),
|
135
|
-
# etc. Multiple types can be strung together: !hshcb (Safari
|
136
|
-
# History and Chrome bookmarks).
|
137
|
-
history_types:
|
138
|
-
- safari_bookmarks
|
139
|
-
- safari_history
|
140
|
-
# - chrome_history
|
141
|
-
# - chrome_bookmarks
|
142
|
-
# - firefox_bookmarks
|
143
|
-
# - firefox_history
|
144
|
-
# - edge_bookmarks
|
145
|
-
# - edge_history
|
146
|
-
# - brave_bookmarks
|
147
|
-
# - brave_history
|
148
|
-
# - arc_history
|
149
|
-
# - arc_bookmarks
|
150
|
-
# Pinboard search
|
151
|
-
# You can find your api key here: https://pinboard.in/settings/password
|
152
|
-
pinboard_api_key: ''
|
153
|
-
# Generate an access token at https://app.bitly.com/settings/api/
|
154
|
-
bitly_access_token: ''
|
155
|
-
bitly_domain: 'bit.ly'
|
156
|
-
# Custom Google API key to use Google search (free for 100 queries/day)
|
157
|
-
google_api_key: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
|
158
118
|
|
159
119
|
ENDCONFIG
|
160
120
|
|
121
|
+
default_config = get_plugin_configs(default_config)
|
122
|
+
|
123
|
+
puts default_config
|
124
|
+
Process.exit 0
|
125
|
+
|
161
126
|
File.open(config_file, "w") do |f|
|
162
127
|
f.puts default_config
|
163
128
|
end
|
@@ -222,15 +187,107 @@ module SL
|
|
222
187
|
|
223
188
|
# use notification center to show progress
|
224
189
|
config["notifications"] ||= false
|
225
|
-
config["pinboard_api_key"] ||= false
|
226
|
-
config["google_api_key"] ||= false
|
227
190
|
|
228
191
|
SL.line_num = nil
|
229
192
|
SL.match_column = nil
|
230
193
|
SL.match_length = nil
|
231
194
|
SL.config = config
|
195
|
+
|
196
|
+
add_plugin_configs(config)
|
197
|
+
end
|
198
|
+
|
199
|
+
# Add plugin configurations to config object
|
200
|
+
#
|
201
|
+
# @param config [Hash] Hash of plugin configurations
|
202
|
+
#
|
203
|
+
# @note applies configurations to SL.config
|
204
|
+
#
|
205
|
+
def add_plugin_configs(config)
|
206
|
+
SL::Searches.plugins[:search].each_value do |plugin|
|
207
|
+
next unless plugin.key?(:config) && !plugin[:config].nil? && !plugin[:config].empty?
|
208
|
+
|
209
|
+
plugin[:config].each do |cfg|
|
210
|
+
SL.config[cfg[:key]] = config[cfg[:key]] if config.key?(cfg[:key])
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
# Add new keys to config if don't exist
|
216
|
+
def write_new_plugin_config
|
217
|
+
default_config = IO.read(config_file)
|
218
|
+
new_config = ""
|
219
|
+
SL::Searches.plugins[:search].each_value do |plugin|
|
220
|
+
next unless plugin.key?(:config) && !plugin[:config].nil? && !plugin[:config].empty?
|
221
|
+
|
222
|
+
plugin[:config].each do |cfg|
|
223
|
+
next if default_config =~ /^(# *)?#{cfg[:key]}:/
|
224
|
+
|
225
|
+
new_config += get_plugin_config(cfg)
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
return if new_config.empty?
|
230
|
+
|
231
|
+
File.open(config_file, "w") { |f| f.puts default_config + new_config }
|
232
|
+
end
|
233
|
+
|
234
|
+
#
|
235
|
+
# Get plugin configs
|
236
|
+
#
|
237
|
+
# @param default_config [String] Existing configuration
|
238
|
+
#
|
239
|
+
# @return [String] default_config with plugin configurations added
|
240
|
+
#
|
241
|
+
def get_plugin_configs(default_config)
|
242
|
+
SL::Searches.plugins[:search].each_value do |plugin|
|
243
|
+
next unless plugin.key?(:config) && !plugin[:config].nil? && !plugin[:config].empty?
|
244
|
+
|
245
|
+
plugin[:config].each do |cfg|
|
246
|
+
new_config = get_plugin_config(cfg)
|
247
|
+
|
248
|
+
default_config += new_config
|
249
|
+
end
|
250
|
+
end
|
251
|
+
default_config
|
252
|
+
end
|
253
|
+
|
254
|
+
#
|
255
|
+
# Get a single plugin configuration
|
256
|
+
#
|
257
|
+
# @param cfg [Hash] Hash of single plugin config
|
258
|
+
#
|
259
|
+
# @return [String] String representation of config
|
260
|
+
#
|
261
|
+
def get_plugin_config(cfg)
|
262
|
+
key = cfg[:key]
|
263
|
+
value = cfg[:value]
|
264
|
+
required = cfg[:required]
|
265
|
+
description = cfg[:description]
|
266
|
+
description = "\n#{description}" if description
|
267
|
+
description = description.word_wrap(60, "# ") if description
|
268
|
+
key = required ? key : "# #{key}"
|
269
|
+
if value.is_a?(Array)
|
270
|
+
array_value = "\n"
|
271
|
+
value.each do |v|
|
272
|
+
array_value += required ? "- #{v.yaml_val}" : "# - #{v.yaml_val}\n"
|
273
|
+
end
|
274
|
+
value = array_value
|
275
|
+
elsif value.is_a?(Hash)
|
276
|
+
hash_value = "\n"
|
277
|
+
value.each do |k, v|
|
278
|
+
hash_value += required ? " #{k}: #{v.yaml_val}" : "# #{k}: #{v.yaml_val}"
|
279
|
+
end
|
280
|
+
value = hash_value
|
281
|
+
else
|
282
|
+
value = value.yaml_val
|
283
|
+
end
|
284
|
+
new_config = ""
|
285
|
+
new_config += description if description
|
286
|
+
|
287
|
+
new_config + "#{key}: #{value}"
|
232
288
|
end
|
233
289
|
|
290
|
+
# Reset configuration
|
234
291
|
def restore_prev_config
|
235
292
|
@prev_config&.each do |k, v|
|
236
293
|
SL.config[k] = v
|
data/lib/searchlink/curl/html.rb
CHANGED
data/lib/searchlink/curl/json.rb
CHANGED
data/lib/searchlink/parse.rb
CHANGED
@@ -151,7 +151,7 @@ module SL
|
|
151
151
|
end
|
152
152
|
terms_p = search_terms.split(/ +/)
|
153
153
|
if terms_p.length > highest_token
|
154
|
-
remainder = terms_p[highest_token - 1
|
154
|
+
remainder = terms_p[highest_token - 1..].join(" ")
|
155
155
|
terms_p = terms_p[0..highest_token - 2]
|
156
156
|
terms_p.push(remainder)
|
157
157
|
end
|
@@ -252,6 +252,28 @@ module SL
|
|
252
252
|
end
|
253
253
|
end
|
254
254
|
|
255
|
+
if input =~ /\[\n(.*?\n)+\]\((.*?)?\)/
|
256
|
+
input.gsub!(/\[\n(((\s*(?:[-+*]|\d+\.)?\s+)*(!\S+ +)?(.*?))\n)+\]\((!\S+.*?)?\)/) do
|
257
|
+
m = Regexp.last_match
|
258
|
+
lines = m[0].split(/\n/)
|
259
|
+
lines = lines[1..-2]
|
260
|
+
lines.map do |l|
|
261
|
+
el_rx = /(\s*(?:[-+*]|\d+\.)?\s+)?(!\S+ )?(\w.*?)$/
|
262
|
+
if l =~ el_rx
|
263
|
+
els = l.match(el_rx)
|
264
|
+
search = if els[2]
|
265
|
+
els[2].strip
|
266
|
+
else
|
267
|
+
m[6] || "!g"
|
268
|
+
end
|
269
|
+
"#{els[1]}[#{els[3].strip}](#{search})"
|
270
|
+
else
|
271
|
+
l
|
272
|
+
end
|
273
|
+
end.join("\n")
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
255
277
|
if input =~ /\[(.*?)\]\((.*?)\)/
|
256
278
|
lines = input.split(/\n/)
|
257
279
|
out = []
|
@@ -263,11 +285,11 @@ module SL
|
|
263
285
|
SL.line_num = num - line_difference
|
264
286
|
@cursor_difference = 0
|
265
287
|
# ignore links in code blocks
|
266
|
-
if line =~ /^( {4,}|\t+)[
|
288
|
+
if line =~ /^(( {4,}|\t+)[^*+-])/
|
267
289
|
out.push(line)
|
268
290
|
next
|
269
291
|
end
|
270
|
-
if line =~
|
292
|
+
if line =~ /^\s*[~`]{3,}/
|
271
293
|
if in_code_block
|
272
294
|
in_code_block = false
|
273
295
|
out.push(line)
|
@@ -287,6 +309,7 @@ module SL
|
|
287
309
|
|
288
310
|
line.gsub!(/\[(.*?)\]\((.*?)\)/) do |match|
|
289
311
|
this_match = Regexp.last_match
|
312
|
+
|
290
313
|
SL.match_column = this_match.begin(0) - @cursor_difference
|
291
314
|
@match_string = this_match.to_s
|
292
315
|
SL.match_length = @match_string.length
|
@@ -605,7 +628,7 @@ module SL
|
|
605
628
|
end
|
606
629
|
terms_p = terms.split(/ +/)
|
607
630
|
if terms_p.length > highest_token
|
608
|
-
remainder = terms_p[highest_token - 1
|
631
|
+
remainder = terms_p[highest_token - 1..].join(" ")
|
609
632
|
terms_p = terms_p[0..highest_token - 2]
|
610
633
|
terms_p.push(remainder)
|
611
634
|
end
|
data/lib/searchlink/plist.rb
CHANGED
@@ -65,18 +65,17 @@ module Plist
|
|
65
65
|
|
66
66
|
def parse
|
67
67
|
plist_tags = PTag.mappings.keys.join("|")
|
68
|
-
start_tag
|
69
|
-
end_tag
|
68
|
+
start_tag = /<(#{plist_tags})([^>]*)>/i
|
69
|
+
end_tag = %r{</(#{plist_tags})[^>]*>}i
|
70
70
|
|
71
71
|
require "strscan"
|
72
72
|
|
73
73
|
@scanner = StringScanner.new(@xml)
|
74
74
|
until @scanner.eos?
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
elsif @scanner.scan(start_tag)
|
75
|
+
next unless @scanner.scan(COMMENT_START)
|
76
|
+
|
77
|
+
@scanner.scan(COMMENT_END)
|
78
|
+
if @scanner.scan(start_tag)
|
80
79
|
@listener.tag_start(@scanner[1], nil)
|
81
80
|
@listener.tag_end(@scanner[1]) if @scanner[2] =~ %r{/$}
|
82
81
|
elsif @scanner.scan(TEXT)
|
@@ -88,117 +87,121 @@ module Plist
|
|
88
87
|
end
|
89
88
|
end
|
90
89
|
end
|
91
|
-
end
|
92
90
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
91
|
+
class PTag
|
92
|
+
@@mappings = {}
|
93
|
+
def self.mappings
|
94
|
+
@@mappings
|
95
|
+
end
|
98
96
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
97
|
+
def self.inherited(sub_class)
|
98
|
+
key = sub_class.to_s.downcase
|
99
|
+
key.gsub!(/^plist::/, "")
|
100
|
+
key.gsub!(/^p/, "") unless key == "plist"
|
103
101
|
|
104
|
-
|
105
|
-
|
102
|
+
@@mappings[key] = sub_class
|
103
|
+
super
|
104
|
+
end
|
106
105
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
106
|
+
attr_accessor :text, :children
|
107
|
+
|
108
|
+
def initialize
|
109
|
+
@children = []
|
110
|
+
end
|
111
111
|
|
112
|
-
|
113
|
-
|
112
|
+
def to_ruby
|
113
|
+
raise "Unimplemented: #{self.class}#to_ruby on #{inspect}"
|
114
|
+
end
|
114
115
|
end
|
115
|
-
end
|
116
116
|
|
117
|
-
|
118
|
-
|
119
|
-
|
117
|
+
class PList < PTag
|
118
|
+
def to_ruby
|
119
|
+
children.first&.to_ruby
|
120
|
+
end
|
120
121
|
end
|
121
|
-
end
|
122
122
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
123
|
+
class PDict < PTag
|
124
|
+
def to_ruby
|
125
|
+
dict = {}
|
126
|
+
key = nil
|
127
127
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
128
|
+
children.each do |c|
|
129
|
+
if key.nil?
|
130
|
+
key = c.to_ruby
|
131
|
+
else
|
132
|
+
dict[key] = c.to_ruby
|
133
|
+
key = nil
|
134
|
+
end
|
134
135
|
end
|
135
|
-
end
|
136
136
|
|
137
|
-
|
137
|
+
dict
|
138
|
+
end
|
138
139
|
end
|
139
|
-
end
|
140
140
|
|
141
|
-
|
142
|
-
|
143
|
-
|
141
|
+
class PKey < PTag
|
142
|
+
def to_ruby
|
143
|
+
CGI.unescapeHTML(text || "")
|
144
|
+
end
|
144
145
|
end
|
145
|
-
end
|
146
146
|
|
147
|
-
|
148
|
-
|
149
|
-
|
147
|
+
class PString < PTag
|
148
|
+
def to_ruby
|
149
|
+
CGI.unescapeHTML(text || "")
|
150
|
+
end
|
150
151
|
end
|
151
|
-
end
|
152
152
|
|
153
|
-
|
154
|
-
|
155
|
-
|
153
|
+
class PArray < PTag
|
154
|
+
def to_ruby
|
155
|
+
children.collect(&:to_ruby)
|
156
|
+
end
|
156
157
|
end
|
157
|
-
end
|
158
158
|
|
159
|
-
|
160
|
-
|
161
|
-
|
159
|
+
class PInteger < PTag
|
160
|
+
def to_ruby
|
161
|
+
text.to_i
|
162
|
+
end
|
162
163
|
end
|
163
|
-
end
|
164
164
|
|
165
|
-
|
166
|
-
|
167
|
-
|
165
|
+
class PTrue < PTag
|
166
|
+
def to_ruby
|
167
|
+
true
|
168
|
+
end
|
168
169
|
end
|
169
|
-
end
|
170
170
|
|
171
|
-
|
172
|
-
|
173
|
-
|
171
|
+
class PFalse < PTag
|
172
|
+
def to_ruby
|
173
|
+
false
|
174
|
+
end
|
174
175
|
end
|
175
|
-
end
|
176
176
|
|
177
|
-
|
178
|
-
|
179
|
-
|
177
|
+
class PReal < PTag
|
178
|
+
def to_ruby
|
179
|
+
text.to_f
|
180
|
+
end
|
180
181
|
end
|
181
|
-
end
|
182
182
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
183
|
+
require "date"
|
184
|
+
|
185
|
+
class PDate < PTag
|
186
|
+
def to_ruby
|
187
|
+
DateTime.parse(text)
|
188
|
+
end
|
187
189
|
end
|
188
|
-
end
|
189
190
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
191
|
+
require "base64"
|
192
|
+
|
193
|
+
class PData < PTag
|
194
|
+
def to_ruby
|
195
|
+
data = Base64.decode64(text.gsub(/\s+/, ""))
|
196
|
+
|
197
|
+
begin
|
198
|
+
Marshal.load(data)
|
199
|
+
rescue Exception
|
200
|
+
io = StringIO.new
|
201
|
+
io.write data
|
202
|
+
io.rewind
|
203
|
+
io
|
204
|
+
end
|
202
205
|
end
|
203
206
|
end
|
204
207
|
end
|
@@ -9,6 +9,14 @@ module SL
|
|
9
9
|
trigger: "a",
|
10
10
|
searches: [
|
11
11
|
["a", "Amazon Search"]
|
12
|
+
],
|
13
|
+
config: [
|
14
|
+
{
|
15
|
+
key: "amazon_partner",
|
16
|
+
value: "bretttercom-20",
|
17
|
+
description: "To create Amazon affiliate links, set amazon_partner to your amazon affiliate tag.",
|
18
|
+
required: true
|
19
|
+
}
|
12
20
|
]
|
13
21
|
}
|
14
22
|
end
|
@@ -10,6 +10,19 @@ module SL
|
|
10
10
|
searches: [
|
11
11
|
["bl", "bit.ly Shorten"],
|
12
12
|
["bitly", "bit.ly shorten"]
|
13
|
+
],
|
14
|
+
config: [
|
15
|
+
{
|
16
|
+
key: "bitly_access_token",
|
17
|
+
value: "xxxx",
|
18
|
+
required: false,
|
19
|
+
description: "Generate an access token at https://app.bitly.com/settings/api/"
|
20
|
+
},
|
21
|
+
{
|
22
|
+
key: "bitly_domain",
|
23
|
+
value: "bit.ly",
|
24
|
+
required: false
|
25
|
+
}
|
13
26
|
]
|
14
27
|
}
|
15
28
|
end
|
@@ -41,6 +41,8 @@ module SL
|
|
41
41
|
terms = "%5C#{search_terms.url_encode}"
|
42
42
|
page = Curl::Html.new("https://duckduckgo.com/?q=#{terms}", compressed: true)
|
43
43
|
|
44
|
+
return false if page.meta["refresh"].nil?
|
45
|
+
|
44
46
|
locs = page.meta["refresh"].match(%r{/l/\?uddg=(.*?)$})
|
45
47
|
locs = page.body.match(%r{/l/\?uddg=(.*?)'}) if locs.nil?
|
46
48
|
locs = page.body.match(/url=(.*?)'/) if locs.nil?
|
@@ -12,6 +12,14 @@ module SL
|
|
12
12
|
["ghu", "GitHub User Search"],
|
13
13
|
["gist", "Gist Search"],
|
14
14
|
["giste", "Gist Embed"]
|
15
|
+
],
|
16
|
+
config: [
|
17
|
+
{
|
18
|
+
key: "github_token",
|
19
|
+
value: "github_patxxxxxxx",
|
20
|
+
require: false,
|
21
|
+
description: "GitHub Personal Access Token (optional)"
|
22
|
+
}
|
15
23
|
]
|
16
24
|
}
|
17
25
|
end
|
@@ -216,7 +224,7 @@ module SL
|
|
216
224
|
else
|
217
225
|
if terms.split(/ +/).count > 1
|
218
226
|
parts = terms.split(/ +/)
|
219
|
-
gist = search_user_gists(parts[0], parts[1
|
227
|
+
gist = search_user_gists(parts[0], parts[1..].join(" "))
|
220
228
|
|
221
229
|
if gist
|
222
230
|
url = gist[:url]
|
@@ -12,6 +12,14 @@ module SL
|
|
12
12
|
searches: [
|
13
13
|
["gg", "Google Search"],
|
14
14
|
["img", "First image from result"]
|
15
|
+
],
|
16
|
+
config: [
|
17
|
+
{
|
18
|
+
key: "google_api_key",
|
19
|
+
value: "xxxxxx",
|
20
|
+
required: false,
|
21
|
+
description: "Custom Google API key to use Google search (free for 100 queries/day)"
|
22
|
+
}
|
15
23
|
]
|
16
24
|
}
|
17
25
|
end
|
@@ -43,6 +51,8 @@ module SL
|
|
43
51
|
return SL.ddg(terms, link_text, google: false, image: image)
|
44
52
|
end
|
45
53
|
|
54
|
+
return false if json["error"] || json["queries"]["request"][0]["totalResults"].to_i.zero? || json["items"].nil?
|
55
|
+
|
46
56
|
unless json["queries"]["request"][0]["totalResults"].to_i.positive?
|
47
57
|
SL.notify("no results", "Google returned no results, defaulting to DuckDuckGo")
|
48
58
|
return SL.ddg(terms, link_text, google: false, image: image)
|
@@ -42,6 +42,32 @@ module SL
|
|
42
42
|
["heb", "Edge Bookmark Search"],
|
43
43
|
["hehb", nil],
|
44
44
|
["hebh", nil]
|
45
|
+
],
|
46
|
+
config: [
|
47
|
+
{
|
48
|
+
description:
|
49
|
+
["Remove or comment (with #) history searches you don't want",
|
50
|
+
"performed by `!h`. You can force-enable them per search, e.g.",
|
51
|
+
"`!hsh` (Safari History only), `!hcb` (Chrome Bookmarks only)",
|
52
|
+
"etc. Multiple types can be strung together: !hshcb (Safari",
|
53
|
+
"History and Chrome bookmarks)"].join(" "),
|
54
|
+
required: false,
|
55
|
+
key: "history_types",
|
56
|
+
value: %w[
|
57
|
+
safari_bookmarks
|
58
|
+
safari_history
|
59
|
+
chrome_history
|
60
|
+
chrome_bookmarks
|
61
|
+
firefox_bookmarks
|
62
|
+
firefox_history
|
63
|
+
edge_bookmarks
|
64
|
+
edge_history
|
65
|
+
brave_bookmarks
|
66
|
+
brave_history
|
67
|
+
arc_history
|
68
|
+
arc_bookmarks
|
69
|
+
]
|
70
|
+
}
|
45
71
|
]
|
46
72
|
}
|
47
73
|
end
|
@@ -30,15 +30,15 @@ module SL
|
|
30
30
|
|
31
31
|
data = Curl::Json.new("https://is.gd/create.php?format=json&url=#{CGI.escape(long_url)}", symbolize_names: true)
|
32
32
|
|
33
|
-
if data.json.key?(
|
34
|
-
SL.add_error(
|
33
|
+
if data.json.key?("errorcode")
|
34
|
+
SL.add_error("Error creating is.gd url", data.json[:errorcode])
|
35
35
|
return [false, title, link_text]
|
36
36
|
end
|
37
37
|
|
38
38
|
link = data.json[:shorturl]
|
39
39
|
rtitle = SL::URL.title(long_url)
|
40
40
|
title = rtitle
|
41
|
-
link_text = rtitle if link_text ==
|
41
|
+
link_text = rtitle if link_text == "" && !SL.titleize
|
42
42
|
[link, title, link_text]
|
43
43
|
end
|
44
44
|
end
|
@@ -17,6 +17,14 @@ module SL
|
|
17
17
|
["itud", "iOS App Store Developer Link"],
|
18
18
|
["mas", "Mac App Store Search"],
|
19
19
|
["masd", "Mac App Store Developer Link"]
|
20
|
+
],
|
21
|
+
config: [
|
22
|
+
{
|
23
|
+
description: "append affiliate link info to iTunes urls, empty quotes for none\nexample:\nitunes_affiliate: '&at=10l4tL&ct=searchlink'",
|
24
|
+
key: "itunes_affiliate",
|
25
|
+
value: "&at=10l4tL&ct=searchlink",
|
26
|
+
required: true
|
27
|
+
}
|
20
28
|
]
|
21
29
|
}
|
22
30
|
end
|
@@ -49,7 +57,6 @@ module SL
|
|
49
57
|
aff ||= SL.config["itunes_affiliate"]
|
50
58
|
|
51
59
|
url = "https://itunes.apple.com/search?term=#{terms.url_encode}&country=#{SL.config['country_code']}&entity=#{entity}&limit=1"
|
52
|
-
puts url
|
53
60
|
begin
|
54
61
|
page = Curl::Json.new(url, compressed: true)
|
55
62
|
json = page.json
|
@@ -21,6 +21,25 @@ module SL
|
|
21
21
|
["lyrice", "Song Lyrics Embed"],
|
22
22
|
["lyricjs", "Song Lyrics JS Embed"]
|
23
23
|
]
|
24
|
+
#
|
25
|
+
# # The config block is optional, but can be used to define any
|
26
|
+
# # configuration options that the plugin requires. New configuration
|
27
|
+
# # options that don't exist in current config will be appended
|
28
|
+
# config: [
|
29
|
+
# {
|
30
|
+
# # Description that will appear above the option in config.yaml
|
31
|
+
# description: "Genius API"
|
32
|
+
# # the configuration key
|
33
|
+
# key: "genius_token",
|
34
|
+
# # the default value
|
35
|
+
# value: "''",
|
36
|
+
# # whether the configuration is required. If
|
37
|
+
# # false (meaning optional), it will be added
|
38
|
+
# # with a # in front of the key in the config
|
39
|
+
# # file, making it a comment.
|
40
|
+
# required: false
|
41
|
+
# }
|
42
|
+
# ]
|
24
43
|
}
|
25
44
|
end
|
26
45
|
|
@@ -10,6 +10,14 @@ module SL
|
|
10
10
|
trigger: "pb",
|
11
11
|
searches: [
|
12
12
|
["pb", "Pinboard Bookmark Search"]
|
13
|
+
],
|
14
|
+
config: [
|
15
|
+
{
|
16
|
+
description: "Pinboard API key.\nYou can find your api key here: https://pinboard.in/settings/password",
|
17
|
+
key: "pinboard_api_key",
|
18
|
+
value: "''",
|
19
|
+
required: true
|
20
|
+
}
|
13
21
|
]
|
14
22
|
}
|
15
23
|
end
|
@@ -26,7 +34,6 @@ module SL
|
|
26
34
|
end
|
27
35
|
|
28
36
|
bookmarks.gsub!(/[\u{1F600}-\u{1F6FF}]/, "")
|
29
|
-
|
30
37
|
bookmarks = JSON.parse(bookmarks)
|
31
38
|
updated = Time.now
|
32
39
|
{ "update_time" => updated, "bookmarks" => bookmarks }
|
@@ -100,8 +107,8 @@ module SL
|
|
100
107
|
def search(_, search_terms, link_text)
|
101
108
|
unless SL.config["pinboard_api_key"]
|
102
109
|
SL.add_error("Missing Pinboard API token",
|
103
|
-
|
104
|
-
to your configuration (pinboard_api_key: YOURKEY)
|
110
|
+
"Find your api key at https://pinboard.in/settings/password and add it
|
111
|
+
to your configuration (pinboard_api_key: YOURKEY)")
|
105
112
|
return false
|
106
113
|
end
|
107
114
|
|
@@ -126,7 +133,7 @@ module SL
|
|
126
133
|
bookmarks.each do |bm|
|
127
134
|
text = [bm["description"], bm["extended"], bm["tags"]].join(" ")
|
128
135
|
|
129
|
-
return [bm["href"], bm["description"]] if text.matches_exact(search_terms)
|
136
|
+
return [bm["href"], bm["description"], link_text] if text.matches_exact(search_terms)
|
130
137
|
end
|
131
138
|
|
132
139
|
return false
|
@@ -158,7 +165,7 @@ module SL
|
|
158
165
|
0
|
159
166
|
end
|
160
167
|
|
161
|
-
return [bm["href"], bm["description"]] if score == 14
|
168
|
+
return [bm["href"], bm["description"], link_text] if score == 14
|
162
169
|
|
163
170
|
next unless score.positive?
|
164
171
|
|
@@ -13,6 +13,15 @@ module SL
|
|
13
13
|
["@l", "LinkedIn Handle"],
|
14
14
|
["@m", "Mastodon Handle"],
|
15
15
|
],
|
16
|
+
config: [
|
17
|
+
description: "Formatting for social links, use %service%, %user%, and %url%
|
18
|
+
E.g. \"%user% on %service%\" => \"ttscoff on Twitter\"
|
19
|
+
\"%service%/%user%\" => \"Twitter/ttscoff\"
|
20
|
+
\"%url%\" => \"twitter.com/ttscoff\"",
|
21
|
+
key: "social_template",
|
22
|
+
value: "%service%/%user%",
|
23
|
+
required: true
|
24
|
+
]
|
16
25
|
}
|
17
26
|
end
|
18
27
|
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module SL
|
4
4
|
# YouTube Search/Linking
|
5
5
|
class YouTubeSearch
|
6
|
-
YOUTUBE_RX = %r{(?:youtu\.be/|youtube\.com/watch\?v=)?(?<id>[a-z0-9_
|
6
|
+
YOUTUBE_RX = %r{(?:youtu\.be/|youtube\.com/watch\?v=)?(?<id>[a-z0-9_-]+)$}i.freeze
|
7
7
|
|
8
8
|
class << self
|
9
9
|
def settings
|
@@ -19,7 +19,7 @@ module SL
|
|
19
19
|
def search(search_type, search_terms, link_text)
|
20
20
|
if SL::URL.url?(search_terms) && search_terms =~ YOUTUBE_RX
|
21
21
|
url = search_terms
|
22
|
-
elsif search_terms =~ /^[a-z0-9_
|
22
|
+
elsif search_terms =~ /^[a-z0-9_-]+$/i
|
23
23
|
url = "https://youtube.com/watch?v=#{search_terms}"
|
24
24
|
else
|
25
25
|
url, title = SL.ddg("site:youtube.com #{search_terms}", link_text)
|
data/lib/searchlink/searches.rb
CHANGED
@@ -53,7 +53,7 @@ module SL
|
|
53
53
|
searches.each do |s|
|
54
54
|
out << "<tr>
|
55
55
|
<td>
|
56
|
-
<code>!#{s[0].is_a?(Array) ? "#{s[0][0]} (#{s[0][1
|
56
|
+
<code>!#{s[0].is_a?(Array) ? "#{s[0][0]} (#{s[0][1..].join(',')})" : s[0]}
|
57
57
|
</code>
|
58
58
|
</td><td>#{s[1]}</td></tr>"
|
59
59
|
end
|
@@ -72,7 +72,7 @@ module SL
|
|
72
72
|
|
73
73
|
searches.each do |s|
|
74
74
|
shortcut = if s[0].is_a?(Array)
|
75
|
-
"#{s[0][0]} (#{s[0][1
|
75
|
+
"#{s[0][0]} (#{s[0][1..].join(',')})"
|
76
76
|
else
|
77
77
|
s[0]
|
78
78
|
end
|
@@ -100,13 +100,13 @@ module SL
|
|
100
100
|
|
101
101
|
def valid_searches
|
102
102
|
searches = []
|
103
|
-
plugins[:search].
|
103
|
+
plugins[:search].each_value { |plugin| searches.push(plugin[:trigger]) }
|
104
104
|
searches
|
105
105
|
end
|
106
106
|
|
107
107
|
def valid_search?(term)
|
108
108
|
valid = false
|
109
|
-
valid = true if term =~ /^(#{valid_searches.join(
|
109
|
+
valid = true if term =~ /^(#{valid_searches.join('|')})$/
|
110
110
|
valid = true if SL.config["custom_site_searches"].keys.include? term
|
111
111
|
# SL.notify("Invalid search#{did_you_mean(term)}", term) unless valid
|
112
112
|
valid
|
@@ -123,6 +123,7 @@ module SL
|
|
123
123
|
plugins[type][title] = {
|
124
124
|
trigger: settings.fetch(:trigger, title).normalize_trigger,
|
125
125
|
searches: settings[:searches],
|
126
|
+
config: settings[:config],
|
126
127
|
class: klass
|
127
128
|
}
|
128
129
|
end
|
@@ -166,7 +167,7 @@ module SL
|
|
166
167
|
end
|
167
168
|
|
168
169
|
def do_search(search_type, search_terms, link_text, timeout: SL.config["timeout"])
|
169
|
-
plugins[:search].
|
170
|
+
plugins[:search].each_value do |plugin|
|
170
171
|
trigger = plugin[:trigger].gsub(/(^\^|\$$)/, "")
|
171
172
|
if search_type =~ /^#{trigger}$/
|
172
173
|
search = proc { plugin[:class].search(search_type, search_terms, link_text) }
|
data/lib/searchlink/string.rb
CHANGED
@@ -3,6 +3,30 @@
|
|
3
3
|
module SL
|
4
4
|
# String helpers
|
5
5
|
class ::String
|
6
|
+
# Quote a YAML value if needed
|
7
|
+
def yaml_val
|
8
|
+
yaml = YAML.safe_load("key: '#{self}'")
|
9
|
+
YAML.dump(yaml).match(/key: (.*?)$/)[1]
|
10
|
+
end
|
11
|
+
|
12
|
+
# Word wrap a string not exceeding max width.
|
13
|
+
# CREDIT: Gavin Kistner, Dayne Broderson
|
14
|
+
#
|
15
|
+
def word_wrap!(col_width = 60, prefix = "")
|
16
|
+
replace dup.word_wrap(col_width, prefix)
|
17
|
+
end
|
18
|
+
|
19
|
+
# As with #word_wrap, but modifies the string in place.
|
20
|
+
#
|
21
|
+
# CREDIT: Gavin Kistner, Dayne Broderson
|
22
|
+
#
|
23
|
+
def word_wrap(col_width = 60, prefix = "")
|
24
|
+
str = dup
|
25
|
+
str.gsub!(/(\S{#{col_width}})(?=\S)/, "#{prefix}\\1")
|
26
|
+
str.gsub!(/(.{1,#{col_width}})(?:\s+|$)/, "#{prefix}\\1\n")
|
27
|
+
str
|
28
|
+
end
|
29
|
+
|
6
30
|
# Scrub invalid characters from string
|
7
31
|
def scrubup
|
8
32
|
encode("utf-16", invalid: :replace).encode("utf-8").gsub(/\u00A0/, " ")
|
@@ -91,7 +115,7 @@ module SL
|
|
91
115
|
## @return { description_of_the_return_value }
|
92
116
|
##
|
93
117
|
def fix_gist_file
|
94
|
-
sub(/^file-/, "").sub(/-([
|
118
|
+
sub(/^file-/, "").sub(/-([^-]+)$/, '.\1')
|
95
119
|
end
|
96
120
|
|
97
121
|
# Turn a string into a slug, removing spaces and
|
@@ -160,7 +184,7 @@ module SL
|
|
160
184
|
# force trailing slash
|
161
185
|
path.sub!(%r{/?$}, "/")
|
162
186
|
# remove last path element
|
163
|
-
path.sub!(%r{/[^/]+[
|
187
|
+
path.sub!(%r{/[^/]+[.-][^/]+/$}, "")
|
164
188
|
# remove starting/ending slashes
|
165
189
|
path.gsub!(%r{(^/|/$)}, "")
|
166
190
|
# split at slashes, delete sections that are shorter
|
@@ -239,7 +263,6 @@ module SL
|
|
239
263
|
|
240
264
|
SL.add_error("Invalid URL", "Could not remove SEO for #{url}")
|
241
265
|
return self
|
242
|
-
|
243
266
|
end
|
244
267
|
|
245
268
|
path = url.path
|
@@ -269,7 +292,6 @@ module SL
|
|
269
292
|
dead_switch = 0
|
270
293
|
|
271
294
|
while title.downcase.gsub(/[^a-z]/i, "") =~ /#{site_re}/i
|
272
|
-
|
273
295
|
break if dead_switch > 5
|
274
296
|
|
275
297
|
seo_title_separators.each_with_index do |sep, i|
|
@@ -277,7 +299,7 @@ module SL
|
|
277
299
|
|
278
300
|
next if parts.length == 1
|
279
301
|
|
280
|
-
remaining_separators = seo_title_separators[i
|
302
|
+
remaining_separators = seo_title_separators[i..].map { |s| Regexp.escape(s) }.join("")
|
281
303
|
seps = Regexp.new("^[^#{remaining_separators}]+$")
|
282
304
|
|
283
305
|
longest = parts.longest_element.strip
|
@@ -411,12 +433,12 @@ module SL
|
|
411
433
|
(1..n).each do |j|
|
412
434
|
(1..m).each do |i|
|
413
435
|
d[i][j] = if s[i - 1] == t[j - 1] # adjust index into string
|
414
|
-
d[i - 1][j - 1]
|
436
|
+
d[i - 1][j - 1] # no operation required
|
415
437
|
else
|
416
438
|
[d[i - 1][j] + 1, # deletion
|
417
439
|
d[i][j - 1] + 1, # insertion
|
418
440
|
d[i - 1][j - 1] + 1 # substitution
|
419
|
-
].min
|
441
|
+
].min
|
420
442
|
end
|
421
443
|
end
|
422
444
|
end
|
data/lib/searchlink/url.rb
CHANGED
@@ -5,6 +5,22 @@ module SL
|
|
5
5
|
# URL module
|
6
6
|
module URL
|
7
7
|
class << self
|
8
|
+
def follow_redirects(url, limit = 5)
|
9
|
+
return url if limit.zero?
|
10
|
+
|
11
|
+
uri = URI.parse(url)
|
12
|
+
response = Net::HTTP.get_response(uri)
|
13
|
+
|
14
|
+
case response
|
15
|
+
when Net::HTTPSuccess
|
16
|
+
response.uri.to_s
|
17
|
+
when Net::HTTPRedirection
|
18
|
+
follow_redirects(response["location"], limit - 1)
|
19
|
+
else
|
20
|
+
url
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
8
24
|
# Validates that a link exists and returns 200
|
9
25
|
def valid_link?(uri_str, limit = 5)
|
10
26
|
return false unless uri_str
|
@@ -130,6 +146,17 @@ module SL
|
|
130
146
|
# end
|
131
147
|
|
132
148
|
begin
|
149
|
+
if url =~ %r{https://(amzn.to|(www\.)?amazon\.com)/}
|
150
|
+
final_url = follow_redirects(url)
|
151
|
+
m = final_url.match(%r{https://www.amazon.com/(.*?)/dp/})
|
152
|
+
title = if m
|
153
|
+
m[1].gsub(/-/, " ")
|
154
|
+
else
|
155
|
+
url.remove_protocol
|
156
|
+
end
|
157
|
+
return title
|
158
|
+
end
|
159
|
+
|
133
160
|
page = Curl::Html.new(url)
|
134
161
|
|
135
162
|
title = page.title || nil
|
@@ -146,7 +173,6 @@ module SL
|
|
146
173
|
title.remove_protocol
|
147
174
|
rescue StandardError
|
148
175
|
SL.add_error("Error retrieving title", "Error determining title for #{url.strip}")
|
149
|
-
warn "Error retrieving title for #{url.strip}"
|
150
176
|
url.remove_protocol
|
151
177
|
end
|
152
178
|
end
|
data/lib/searchlink/version.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module SL
|
4
|
-
VERSION =
|
4
|
+
VERSION = "2.3.82"
|
5
5
|
end
|
6
6
|
|
7
7
|
# Main module
|
@@ -44,7 +44,11 @@ module SL
|
|
44
44
|
"Accept" => "application/vnd.github+json",
|
45
45
|
"X-GitHub-Api-Version" => "2022-11-28",
|
46
46
|
}
|
47
|
-
|
47
|
+
if defined? Secrets::GH_AUTH_TOKEN
|
48
|
+
headers["Authorization"] = "Bearer #{Secrets::GH_AUTH_TOKEN}"
|
49
|
+
elsif SL.config["github_token"]
|
50
|
+
headers["Authorization"] = "Bearer #{SL.settings["github_token"]}"
|
51
|
+
end
|
48
52
|
|
49
53
|
url = "https://api.github.com/repos/ttscoff/searchlink/releases/latest"
|
50
54
|
page = Curl::Json.new(url, headers: headers)
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: searchlink
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.3.
|
4
|
+
version: 2.3.82
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brett Terpstra
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-01-06 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: base64
|
@@ -248,6 +247,20 @@ dependencies:
|
|
248
247
|
- - "~>"
|
249
248
|
- !ruby/object:Gem::Version
|
250
249
|
version: 0.9.5
|
250
|
+
- !ruby/object:Gem::Dependency
|
251
|
+
name: pastel
|
252
|
+
requirement: !ruby/object:Gem::Requirement
|
253
|
+
requirements:
|
254
|
+
- - "~>"
|
255
|
+
- !ruby/object:Gem::Version
|
256
|
+
version: '0.8'
|
257
|
+
type: :development
|
258
|
+
prerelease: false
|
259
|
+
version_requirements: !ruby/object:Gem::Requirement
|
260
|
+
requirements:
|
261
|
+
- - "~>"
|
262
|
+
- !ruby/object:Gem::Version
|
263
|
+
version: '0.8'
|
251
264
|
description: macOS System Service for inline web searches
|
252
265
|
email:
|
253
266
|
- me@brettterpstra.com
|
@@ -301,6 +314,7 @@ files:
|
|
301
314
|
- lib/searchlink/searches/youtube.rb
|
302
315
|
- lib/searchlink/semver.rb
|
303
316
|
- lib/searchlink/string.rb
|
317
|
+
- lib/searchlink/tokens.rb
|
304
318
|
- lib/searchlink/url.rb
|
305
319
|
- lib/searchlink/util.rb
|
306
320
|
- lib/searchlink/version.rb
|
@@ -309,7 +323,6 @@ homepage: https://github.com/ttscoff/searchlink
|
|
309
323
|
licenses:
|
310
324
|
- MIT
|
311
325
|
metadata: {}
|
312
|
-
post_install_message:
|
313
326
|
rdoc_options: []
|
314
327
|
require_paths:
|
315
328
|
- lib
|
@@ -324,8 +337,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
324
337
|
- !ruby/object:Gem::Version
|
325
338
|
version: '0'
|
326
339
|
requirements: []
|
327
|
-
rubygems_version: 3.
|
328
|
-
signing_key:
|
340
|
+
rubygems_version: 3.6.2
|
329
341
|
specification_version: 4
|
330
342
|
summary: Create Markdown links from web searches without leaving your editor.
|
331
343
|
test_files: []
|