searchlink 2.3.60 → 2.3.62
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 +13 -3
- data/lib/searchlink/searches.rb +23 -10
- data/lib/searchlink/util.rb +1 -1
- data/lib/searchlink/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20591719c33fd31a48e40072d839ea484f13fec80789fccee1417108e0e4f9f4
|
4
|
+
data.tar.gz: ff92074f65ad60d2bb52016169f9cb5d61d4ef3696130195f8ef1dfeb8b0635b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06fd6071642386fed86432d1b18ccac1d7ebad0dbdcdfb8c8e5e244431d7e190039b6b53e2ce75654bef4512c28b67ba5f7d4d56c6f728bd7387bb7d74eeb5e9
|
7
|
+
data.tar.gz: 6d7e73ece33947326e6ff610af6c71cf8f7d113650c447bb2d97409095d780b54c3ebc5b3a6cb2da4a075e03684e02d1ff0bef1a301a8f4576576a8329b4e4db
|
data/lib/searchlink/config.rb
CHANGED
@@ -17,10 +17,20 @@ module SL
|
|
17
17
|
class SearchLink
|
18
18
|
# Values found in ~/.searchlink will override defaults in
|
19
19
|
# this script
|
20
|
+
def config_file
|
21
|
+
old_style = File.expand_path('~/.searchlink')
|
22
|
+
new_style = File.expand_path('~/.config/searchlink/config.yaml')
|
23
|
+
if File.exist?(old_style) && !File.exist?(new_style)
|
24
|
+
old_style
|
25
|
+
else
|
26
|
+
FileUtils.mkdir_p(File.dirname(new_style))
|
27
|
+
new_style
|
28
|
+
end
|
29
|
+
end
|
20
30
|
|
21
31
|
def initialize(opt = {})
|
22
32
|
SL.printout = opt[:echo] || false
|
23
|
-
unless File.exist?
|
33
|
+
unless File.exist? config_file
|
24
34
|
default_config = <<~ENDCONFIG
|
25
35
|
# set to true to have an HTML comment included detailing any errors
|
26
36
|
# Can be disabled per search with `--d`, or enabled with `++d`.
|
@@ -146,12 +156,12 @@ module SL
|
|
146
156
|
|
147
157
|
ENDCONFIG
|
148
158
|
|
149
|
-
File.open(
|
159
|
+
File.open(config_file, 'w') do |f|
|
150
160
|
f.puts default_config
|
151
161
|
end
|
152
162
|
end
|
153
163
|
|
154
|
-
config = YAML.load_file(
|
164
|
+
config = YAML.load_file(config_file)
|
155
165
|
|
156
166
|
# set to true to have an HTML comment inserted showing any errors
|
157
167
|
config['debug'] ||= false
|
data/lib/searchlink/searches.rb
CHANGED
@@ -24,9 +24,9 @@ module SL
|
|
24
24
|
def description_for_search(search_type)
|
25
25
|
description = "#{search_type} search"
|
26
26
|
plugins[:search].each do |_, plugin|
|
27
|
-
|
28
|
-
unless
|
29
|
-
description =
|
27
|
+
search = plugin[:searches].select { |s| s[0].is_a?(Array) ? s[0].include?(search_type) : s[0] == search_type }
|
28
|
+
unless search.empty?
|
29
|
+
description = search[0][1]
|
30
30
|
break
|
31
31
|
end
|
32
32
|
end
|
@@ -42,11 +42,14 @@ module SL
|
|
42
42
|
searches = plugins[:search]
|
43
43
|
.flat_map { |_, plugin| plugin[:searches] }
|
44
44
|
.reject { |s| s[1].nil? }
|
45
|
-
.sort_by { |s| s[0] }
|
45
|
+
.sort_by { |s| s[0].is_a?(Array) ? s[0][0] : s[0] }
|
46
46
|
out = ['<table id="searches">',
|
47
47
|
'<thead><td>Shortcut</td><td>Search Type</td></thead>',
|
48
48
|
'<tbody>']
|
49
|
-
|
49
|
+
|
50
|
+
searches.each do |s|
|
51
|
+
out << "<tr><td><code>!#{s[0].is_a?(Array) ? "#{s[0][0]} (#{s[0][1..].join(',')})" : s[0]}</code></td><td>#{s[1]}</td></tr>"
|
52
|
+
end
|
50
53
|
out.concat(['</tbody>', '</table>']).join("\n")
|
51
54
|
end
|
52
55
|
|
@@ -58,9 +61,11 @@ module SL
|
|
58
61
|
def available_searches
|
59
62
|
searches = []
|
60
63
|
plugins[:search].each { |_, plugin| searches.concat(plugin[:searches].delete_if { |s| s[1].nil? }) }
|
61
|
-
out =
|
62
|
-
searches.each
|
63
|
-
|
64
|
+
out = []
|
65
|
+
searches.each do |s|
|
66
|
+
out += "!#{s[0].is_a?(Array) ? "#{s[0][0]} (#{s[0][1..].join(',')})" : s[0]}#{s[0].spacer}#{s[1]}"
|
67
|
+
end
|
68
|
+
out.join("\n")
|
64
69
|
end
|
65
70
|
|
66
71
|
def best_search_match(term)
|
@@ -110,9 +115,17 @@ module SL
|
|
110
115
|
|
111
116
|
def load_custom
|
112
117
|
plugins_folder = File.expand_path('~/.local/searchlink/plugins')
|
113
|
-
|
118
|
+
new_plugins_folder = File.expand_path('~/.config/searchlink/plugins')
|
119
|
+
|
120
|
+
if File.directory?(plugins_folder) && !File.directory?(new_plugins_folder)
|
121
|
+
Dir.glob(File.join(plugins_folder, '**/*.rb')).sort.each do |plugin|
|
122
|
+
require plugin
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
return unless File.directory?(new_plugins_folder)
|
114
127
|
|
115
|
-
Dir.glob(File.join(
|
128
|
+
Dir.glob(File.join(new_plugins_folder, '**/*.rb')).sort.each do |plugin|
|
116
129
|
require plugin
|
117
130
|
end
|
118
131
|
end
|
data/lib/searchlink/util.rb
CHANGED
@@ -78,7 +78,7 @@ module SL
|
|
78
78
|
## @return [String] path to new cache file
|
79
79
|
##
|
80
80
|
def cache_file_for(filename)
|
81
|
-
cache_folder = File.expand_path('~/.
|
81
|
+
cache_folder = File.expand_path('~/.config/searchlink/cache')
|
82
82
|
FileUtils.mkdir_p(cache_folder) unless File.directory?(cache_folder)
|
83
83
|
File.join(cache_folder, filename.sub(/(\.cache)?$/, '.cache'))
|
84
84
|
end
|
data/lib/searchlink/version.rb
CHANGED