searchlink 2.3.59

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/bin/searchlink +84 -0
  3. data/lib/searchlink/array.rb +7 -0
  4. data/lib/searchlink/config.rb +230 -0
  5. data/lib/searchlink/curl/html.rb +482 -0
  6. data/lib/searchlink/curl/json.rb +90 -0
  7. data/lib/searchlink/curl.rb +7 -0
  8. data/lib/searchlink/help.rb +103 -0
  9. data/lib/searchlink/output.rb +270 -0
  10. data/lib/searchlink/parse.rb +668 -0
  11. data/lib/searchlink/plist.rb +213 -0
  12. data/lib/searchlink/search.rb +70 -0
  13. data/lib/searchlink/searches/amazon.rb +25 -0
  14. data/lib/searchlink/searches/applemusic.rb +123 -0
  15. data/lib/searchlink/searches/bitly.rb +50 -0
  16. data/lib/searchlink/searches/definition.rb +67 -0
  17. data/lib/searchlink/searches/duckduckgo.rb +167 -0
  18. data/lib/searchlink/searches/github.rb +245 -0
  19. data/lib/searchlink/searches/google.rb +67 -0
  20. data/lib/searchlink/searches/helpers/chromium.rb +318 -0
  21. data/lib/searchlink/searches/helpers/firefox.rb +135 -0
  22. data/lib/searchlink/searches/helpers/safari.rb +133 -0
  23. data/lib/searchlink/searches/history.rb +166 -0
  24. data/lib/searchlink/searches/hook.rb +77 -0
  25. data/lib/searchlink/searches/itunes.rb +97 -0
  26. data/lib/searchlink/searches/lastfm.rb +41 -0
  27. data/lib/searchlink/searches/lyrics.rb +91 -0
  28. data/lib/searchlink/searches/pinboard.rb +183 -0
  29. data/lib/searchlink/searches/social.rb +105 -0
  30. data/lib/searchlink/searches/software.rb +27 -0
  31. data/lib/searchlink/searches/spelling.rb +59 -0
  32. data/lib/searchlink/searches/spotlight.rb +28 -0
  33. data/lib/searchlink/searches/stackoverflow.rb +31 -0
  34. data/lib/searchlink/searches/tmdb.rb +52 -0
  35. data/lib/searchlink/searches/twitter.rb +46 -0
  36. data/lib/searchlink/searches/wikipedia.rb +33 -0
  37. data/lib/searchlink/searches/youtube.rb +48 -0
  38. data/lib/searchlink/searches.rb +194 -0
  39. data/lib/searchlink/semver.rb +140 -0
  40. data/lib/searchlink/string.rb +469 -0
  41. data/lib/searchlink/url.rb +153 -0
  42. data/lib/searchlink/util.rb +87 -0
  43. data/lib/searchlink/version.rb +93 -0
  44. data/lib/searchlink/which.rb +175 -0
  45. data/lib/searchlink.rb +66 -0
  46. data/lib/tokens.rb +3 -0
  47. metadata +299 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: afaa2c476c0dea9ca4af8d6049a6235c3aabf265fc512f61ec091343f0913cfa
4
+ data.tar.gz: 94d56d4f5af396e1fc71e564c35d25bbaee4540a039e73030f3623e32a03d9cf
5
+ SHA512:
6
+ metadata.gz: 70f776838f8735da2c152ead9d4178efa82d6c072ea2207bd0608bc116d84f30daa7170675412ec0e65611f5278bbd6eb8bec25324603a98fdaaae2941ab6894
7
+ data.tar.gz: f6d8d843f6e141caf38b1e1ac45fa7d244d19e01584d04f9fdee9f2b8dc9fe9ebf44a6a88bdbcc6403b9c5b8f09d6c526e8eb89780114e2f7a33de0515a981a5
data/bin/searchlink ADDED
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ SILENT = ENV['SL_SILENT'] =~ /false/i ? false : true
5
+ $LOAD_PATH.unshift File.join(__dir__, '..')
6
+
7
+ # import
8
+ require 'lib/searchlink'
9
+
10
+ if RUBY_VERSION.to_f > 1.9
11
+ Encoding.default_external = Encoding::UTF_8
12
+ Encoding.default_internal = Encoding::UTF_8
13
+ end
14
+
15
+ sl = SL::SearchLink.new({ echo: false })
16
+
17
+ SL::Searches.load_custom
18
+
19
+ # # ignore
20
+ # SL::Searches.load_searches
21
+
22
+ overwrite = true
23
+ backup = SL.config['backup']
24
+
25
+ if !ARGV.empty?
26
+ files = []
27
+ ARGV.each do |arg|
28
+ case arg
29
+ when /^(--?)?h(elp)?$/
30
+ print SL.version_check
31
+ puts
32
+ sl.help_cli
33
+ $stdout.puts 'See https://github.com/ttscoff/searchlink/wiki for help'
34
+ Process.exit
35
+ when /^(--?)?v(er(s(ion)?)?)?$/
36
+ print SL.version_check
37
+ Process.exit
38
+ when /^--?(stdout)$/
39
+ overwrite = false
40
+ when /^--?no[\-_]backup$/
41
+ backup = false
42
+ else
43
+ files.push(arg)
44
+ end
45
+ end
46
+
47
+ files.each do |file|
48
+ if File.exist?(file) && `file -b "#{file}"|grep -c text`.to_i.positive?
49
+ input = RUBY_VERSION.to_f > 1.9 ? IO.read(file).force_encoding('utf-8') : IO.read(file)
50
+
51
+ backup_file = "#{file}.bak"
52
+ backup_file = "#{file}.bak 1" if File.exist?(backup_file)
53
+ backup_file.next! while File.exist?(backup_file)
54
+
55
+ FileUtils.cp(file, backup_file) if backup && overwrite
56
+
57
+ sl.parse(input)
58
+ output = SL.output&.join('')
59
+
60
+ next unless output
61
+
62
+ if overwrite
63
+ File.open(file, 'w') do |f|
64
+ f.puts output
65
+ end
66
+ else
67
+ puts output || input
68
+ end
69
+ else
70
+ warn "Error reading #{file}"
71
+ end
72
+ end
73
+ else
74
+ input = RUBY_VERSION.to_f > 1.9 ? $stdin.read.force_encoding('utf-8').encode : $stdin.read
75
+
76
+ sl.parse(input)
77
+ output = SL.output&.join('')
78
+
79
+ if SL.clipboard
80
+ print input
81
+ else
82
+ print output
83
+ end
84
+ end
@@ -0,0 +1,7 @@
1
+ # Array helpers
2
+ class ::Array
3
+ # Finds the longest element in a given array.
4
+ def longest_element
5
+ group_by(&:size).max.last[0]
6
+ end
7
+ end
@@ -0,0 +1,230 @@
1
+ module SL
2
+ class << self
3
+ attr_writer :config, :prev_config
4
+
5
+ def config
6
+ @config ||= SL::SearchLink.new({ echo: true })
7
+ end
8
+
9
+ def prev_config
10
+ @prev_config ||= {}
11
+ end
12
+ end
13
+ end
14
+
15
+ module SL
16
+ # Main SearchLink class
17
+ class SearchLink
18
+ # Values found in ~/.searchlink will override defaults in
19
+ # this script
20
+
21
+ def initialize(opt = {})
22
+ SL.printout = opt[:echo] || false
23
+ unless File.exist? File.expand_path('~/.searchlink')
24
+ default_config = <<~ENDCONFIG
25
+ # set to true to have an HTML comment included detailing any errors
26
+ # Can be disabled per search with `--d`, or enabled with `++d`.
27
+ debug: true
28
+ # set to true to have an HTML comment included reporting results
29
+ report: true
30
+
31
+ # use Notification Center to display progress
32
+ notifications: false
33
+
34
+ # when running on a file, back up original to *.bak
35
+ backup: true
36
+
37
+ # Time limit for searches. Increase if your searches are regularly
38
+ # timing out
39
+ timeout: 15
40
+
41
+ # change this to set a specific country for search (default US)
42
+ country_code: US
43
+
44
+ # set to true to force inline Markdown links. Can be disabled
45
+ # per search with `--i`, or enabled with `++i`
46
+ inline: false
47
+
48
+ # set to true to include a random string in reference titles.
49
+ # Avoids conflicts if you're only running on part of a document
50
+ # or using SearchLink multiple times within a document
51
+ prefix_random: true
52
+
53
+ # set to true to add titles to links based on the page title
54
+ # of the search result. Can be disabled per search with `--t`,
55
+ # or enabled with `++t`.
56
+ include_titles: false
57
+
58
+ # set to true to attempt to remove SEO elements from page titles,
59
+ # such that "Regular expressions for beginners | Brett Terpstra.com"
60
+ # becomes "Regular expressions for beginners"
61
+ remove_seo: false
62
+
63
+ # confirm existence (200) of generated links. Can be disabled
64
+ # per search with `--v`, or enabled with `++v`.
65
+ validate_links: false
66
+
67
+ # If the link text is left empty, always insert the page title
68
+ # E.g. [](!g Search Text)
69
+ empty_uses_page_title: false
70
+
71
+ # Formatting for social links, use %service%, %user%, and %url%
72
+ # E.g. "%user% on %service%" => "ttscoff on Twitter"
73
+ # "%service%/%user%" => "Twitter/ttscoff"
74
+ # "%url%" => "twitter.com/ttscoff"
75
+ social_template: "%service%/%user%"
76
+
77
+ # append affiliate link info to iTunes urls, empty quotes for none
78
+ # example:
79
+ # itunes_affiliate: "&at=10l4tL&ct=searchlink"
80
+ itunes_affiliate: "&at=10l4tL&ct=searchlink"
81
+
82
+ # to create Amazon affiliate links, set amazon_partner to your amazon
83
+ # affiliate tag
84
+ # amazon_partner: "bretttercom-20"
85
+ amazon_partner: "bretttercom-20"
86
+
87
+ # To create custom abbreviations for Google Site Searches,
88
+ # add to (or replace) the hash below.
89
+ # "abbreviation" => "site.url",
90
+ # This allows you, for example to use [search term](!bt)
91
+ # as a shortcut to search brettterpstra.com (using a site-specific
92
+ # Google search). Keys in this list can override existing
93
+ # search trigger abbreviations.
94
+ #
95
+ # If a custom search starts with "http" or "/", it becomes
96
+ # a simple replacement. Any instance of "$term" is replaced
97
+ # with a URL-escaped version of your search terms.
98
+ # Use $term1, $term2, etc. to replace in sequence from
99
+ # multiple search terms. No instances of "$term" functions
100
+ # as a simple shortcut. "$term" followed by a "d" lowercases
101
+ # the replacement. Use "$term1d," "$term2d" to downcase
102
+ # sequential replacements (affected individually).
103
+ # Long flags (e.g. --no-validate_links) can be used after
104
+ # any url in the custom searches.
105
+ #
106
+ # Use $terms to slugify all search terms, turning
107
+ # "Markdown Service Tools" into "markdown-service-tools"
108
+ custom_site_searches:
109
+ bt: brettterpstra.com
110
+ btt: https://brettterpstra.com/topic/$term1d
111
+ bts: /search/$term --no-validate_links
112
+ md: www.macdrifter.com
113
+ ms: macstories.net
114
+ dd: www.leancrew.com
115
+ spark: macsparky.com
116
+ man: http://man.cx/$term
117
+ dev: developer.apple.com
118
+ nq: http://nerdquery.com/?media_only=0&query=$term&search=1&category=-1&catid=&type=and&results=50&db=0&prefix=0
119
+ gs: http://scholar.google.com/scholar?btnI&hl=en&q=$term&btnG=&as_sdt=80006
120
+ # Remove or comment (with #) history searches you don't want
121
+ # performed by `!h`. You can force-enable them per search, e.g.
122
+ # `!hsh` (Safari History only), `!hcb` (Chrome Bookmarks only),
123
+ # etc. Multiple types can be strung together: !hshcb (Safari
124
+ # History and Chrome bookmarks).
125
+ history_types:
126
+ - safari_bookmarks
127
+ - safari_history
128
+ # - chrome_history
129
+ # - chrome_bookmarks
130
+ # - firefox_bookmarks
131
+ # - firefox_history
132
+ # - edge_bookmarks
133
+ # - edge_history
134
+ # - brave_bookmarks
135
+ # - brave_history
136
+ # - arc_history
137
+ # - arc_bookmarks
138
+ # Pinboard search
139
+ # You can find your api key here: https://pinboard.in/settings/password
140
+ pinboard_api_key: ''
141
+ # Generate an access token at https://app.bitly.com/settings/api/
142
+ bitly_access_token: ''
143
+ bitly_domain: 'bit.ly'
144
+ # Custom Google API key to use Google search (free for 100 queries/day)
145
+ google_api_key: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
146
+
147
+ ENDCONFIG
148
+
149
+ File.open(File.expand_path('~/.searchlink'), 'w') do |f|
150
+ f.puts default_config
151
+ end
152
+ end
153
+
154
+ config = YAML.load_file(File.expand_path('~/.searchlink'))
155
+
156
+ # set to true to have an HTML comment inserted showing any errors
157
+ config['debug'] ||= false
158
+
159
+ # set to true to get a verbose report at the end of multi-line processing
160
+ config['report'] ||= false
161
+
162
+ config['backup'] = true unless config.key? 'backup'
163
+
164
+ config['timeout'] ||= 15
165
+
166
+ # set to true to force inline links
167
+ config['inline'] ||= false
168
+
169
+ # set to true to add titles to links based on site title
170
+ config['include_titles'] ||= false
171
+
172
+ # set to true to remove SEO elements from page titles
173
+ config['remove_seo'] ||= false
174
+
175
+ # set to true to use page title as link text when empty
176
+ config['empty_uses_page_title'] ||= false
177
+
178
+ # change this to set a specific country for search (default US)
179
+ config['country_code'] ||= 'US'
180
+
181
+ # set to true to include a random string in ref titles
182
+ # allows running SearchLink multiple times w/out conflicts
183
+ config['prefix_random'] = false unless config['prefix_random']
184
+
185
+ config['social_template'] ||= '%service%/%user%'
186
+
187
+ # append affiliate link info to iTunes urls, empty quotes for none
188
+ # example:
189
+ # $itunes_affiliate = "&at=10l4tL&ct=searchlink"
190
+ config['itunes_affiliate'] ||= '&at=10l4tL&ct=searchlink'
191
+
192
+ # to create Amazon affiliate links, set amazon_partner to your amazon
193
+ # affiliate tag
194
+ # amazon_partner: "bretttercom-20"
195
+ config['amazon_partner'] ||= ''
196
+
197
+ # To create custom abbreviations for Google Site Searches,
198
+ # add to (or replace) the hash below.
199
+ # "abbreviation" => "site.url",
200
+ # This allows you, for example to use [search term](!bt)
201
+ # as a shortcut to search brettterpstra.com. Keys in this
202
+ # hash can override existing search triggers.
203
+ config['custom_site_searches'] ||= {
204
+ 'bt' => 'brettterpstra.com',
205
+ 'imdb' => 'imdb.com'
206
+ }
207
+
208
+ # confirm existence of links generated from custom search replacements
209
+ config['validate_links'] ||= false
210
+
211
+ # use notification center to show progress
212
+ config['notifications'] ||= false
213
+ config['pinboard_api_key'] ||= false
214
+ config['google_api_key'] ||= false
215
+
216
+ SL.line_num = nil
217
+ SL.match_column = nil
218
+ SL.match_length = nil
219
+ SL.config = config
220
+ end
221
+
222
+ def restore_prev_config
223
+ @prev_config&.each do |k, v|
224
+ SL.config[k] = v
225
+ $stderr.print "\r\033[0KReset config: #{k} = #{SL.config[k]}\n" unless SILENT
226
+ end
227
+ @prev_config = {}
228
+ end
229
+ end
230
+ end