searchlink 2.3.59 → 2.3.61
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/searchlink +5 -4
- data/lib/searchlink/array.rb +24 -2
- data/lib/searchlink/config.rb +12 -3
- data/lib/searchlink/searches.rb +19 -9
- data/lib/searchlink/string.rb +10 -0
- 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: cff5bedf7ccbc233a648654e9f3c7bf41981a451c11ddfb6b1fd90741ae6ae2a
|
4
|
+
data.tar.gz: 41e05ed7af669c38d093eb5f109489a786e5bef29575caade95c8328332abf06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1fcb8a00815275b8263805029d47d50d8fd5d934de2880dcfb32c41384652c5791a0c2415e5cead7b2649c348b5374f050d2a4f74b817b8399e25efd5bc72912
|
7
|
+
data.tar.gz: c65f32af3fdeca3ea36306b92babcaa09cfb4c1aee01c5569a1dcf8132821d9b94a05e9f186961a2e67990db6ec409b22562b12e73ef7ca4517036263a8bc642
|
data/bin/searchlink
CHANGED
@@ -31,13 +31,13 @@ if !ARGV.empty?
|
|
31
31
|
puts
|
32
32
|
sl.help_cli
|
33
33
|
$stdout.puts 'See https://github.com/ttscoff/searchlink/wiki for help'
|
34
|
-
Process.exit
|
34
|
+
Process.exit 0
|
35
35
|
when /^(--?)?v(er(s(ion)?)?)?$/
|
36
36
|
print SL.version_check
|
37
|
-
Process.exit
|
37
|
+
Process.exit 0
|
38
38
|
when /^--?(stdout)$/
|
39
39
|
overwrite = false
|
40
|
-
when /^--?no[
|
40
|
+
when /^--?no[-_]backup$/
|
41
41
|
backup = false
|
42
42
|
else
|
43
43
|
files.push(arg)
|
@@ -47,6 +47,7 @@ if !ARGV.empty?
|
|
47
47
|
files.each do |file|
|
48
48
|
if File.exist?(file) && `file -b "#{file}"|grep -c text`.to_i.positive?
|
49
49
|
input = RUBY_VERSION.to_f > 1.9 ? IO.read(file).force_encoding('utf-8') : IO.read(file)
|
50
|
+
input.scrub!
|
50
51
|
|
51
52
|
backup_file = "#{file}.bak"
|
52
53
|
backup_file = "#{file}.bak 1" if File.exist?(backup_file)
|
@@ -72,7 +73,7 @@ if !ARGV.empty?
|
|
72
73
|
end
|
73
74
|
else
|
74
75
|
input = RUBY_VERSION.to_f > 1.9 ? $stdin.read.force_encoding('utf-8').encode : $stdin.read
|
75
|
-
|
76
|
+
input.scrub!
|
76
77
|
sl.parse(input)
|
77
78
|
output = SL.output&.join('')
|
78
79
|
|
data/lib/searchlink/array.rb
CHANGED
@@ -1,7 +1,29 @@
|
|
1
1
|
# Array helpers
|
2
2
|
class ::Array
|
3
|
-
# Finds the longest element in
|
3
|
+
# Finds the longest element in an array of strings
|
4
|
+
#
|
5
|
+
# @return [String] first element among longest elements
|
4
6
|
def longest_element
|
5
|
-
|
7
|
+
longest_elements[0]
|
8
|
+
end
|
9
|
+
# Finds the longest elements and returns an Array
|
10
|
+
#
|
11
|
+
# @return [Array] array of longest elements
|
12
|
+
def longest_elements
|
13
|
+
group_by(&:size).max.last
|
14
|
+
end
|
15
|
+
|
16
|
+
# Finds the shortest element in an array of strings
|
17
|
+
#
|
18
|
+
# @return [String] first element among shortest elements
|
19
|
+
def shortest_element
|
20
|
+
shortest_elements[0]
|
21
|
+
end
|
22
|
+
|
23
|
+
# Finds the shortest elements in an array of strings
|
24
|
+
#
|
25
|
+
# @return [Array] array of shortest elements
|
26
|
+
def shortest_elements
|
27
|
+
group_by(&:size).min.last
|
6
28
|
end
|
7
29
|
end
|
data/lib/searchlink/config.rb
CHANGED
@@ -17,10 +17,19 @@ 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)
|
24
|
+
return old_style
|
25
|
+
else
|
26
|
+
return new_style
|
27
|
+
end
|
28
|
+
end
|
20
29
|
|
21
30
|
def initialize(opt = {})
|
22
31
|
SL.printout = opt[:echo] || false
|
23
|
-
unless File.exist?
|
32
|
+
unless File.exist? config_file
|
24
33
|
default_config = <<~ENDCONFIG
|
25
34
|
# set to true to have an HTML comment included detailing any errors
|
26
35
|
# Can be disabled per search with `--d`, or enabled with `++d`.
|
@@ -146,12 +155,12 @@ module SL
|
|
146
155
|
|
147
156
|
ENDCONFIG
|
148
157
|
|
149
|
-
File.open(
|
158
|
+
File.open(config_file, 'w') do |f|
|
150
159
|
f.puts default_config
|
151
160
|
end
|
152
161
|
end
|
153
162
|
|
154
|
-
config = YAML.load_file(
|
163
|
+
config = YAML.load_file(config_file)
|
155
164
|
|
156
165
|
# set to true to have an HTML comment inserted showing any errors
|
157
166
|
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,7 +115,12 @@ module SL
|
|
110
115
|
|
111
116
|
def load_custom
|
112
117
|
plugins_folder = File.expand_path('~/.local/searchlink/plugins')
|
113
|
-
|
118
|
+
|
119
|
+
Dir.glob(File.join(plugins_folder, '**/*.rb')).sort.each do |plugin|
|
120
|
+
require plugin
|
121
|
+
end
|
122
|
+
|
123
|
+
plugins_folder = File.expand_path('~/.config/searchlink/plugins')
|
114
124
|
|
115
125
|
Dir.glob(File.join(plugins_folder, '**/*.rb')).sort.each do |plugin|
|
116
126
|
require plugin
|
data/lib/searchlink/string.rb
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# String helpers
|
2
2
|
class ::String
|
3
|
+
# Scrub invalid characters from string
|
4
|
+
def scrub
|
5
|
+
encode('utf-16', invalid: :replace).encode('utf-8')
|
6
|
+
end
|
7
|
+
|
8
|
+
# @see #scrub
|
9
|
+
def scrub!
|
10
|
+
replace scrub
|
11
|
+
end
|
12
|
+
|
3
13
|
# URL Encode string
|
4
14
|
#
|
5
15
|
# @return [String] url encoded string
|
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