hiiro 0.1.13 → 0.1.14

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/h-link +45 -3
  3. data/lib/hiiro/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 80d5d0cdd946b7aecc0994b6a5bb970b3857f9e0049a6f2bb2908dc7713dc325
4
- data.tar.gz: 9238058ff310eef9ebe8595fca12c872aaf9668299d29990750a18f54d9e2f1a
3
+ metadata.gz: 120a159138b041e06749ec822d31251a980ff168177a23e62d118ce64a9aa7a3
4
+ data.tar.gz: 6e4fbc826a0fc648bc1dd53da2165daf15b081875bce912ff6d8933ca56f5662
5
5
  SHA512:
6
- metadata.gz: 39531bfa736dd54743fef4b2a5286137ceb6d4cc9ff14b77b0c8d6217e12e1b623953f78da41acc08d56aff3b622986a326455805d0096969c315f36d69dbed5
7
- data.tar.gz: 969631679249c0f5d8f0fc0f377536a0aafa000e0e4a3d6ce7d34e9b03ec88282f3121a725aaccbf47d3bcc1ab10cff2e43e1e022bd3de237382a57f9f8f91de
6
+ metadata.gz: 0b943ab68f08a7db203c94c5d1f1b096e0ef0bcc3bdb30ba7556e49bd86cd5b398b87cf6181d676bf609870c11df3aaa124f74035fbc636566f3a21fcfe3a107
7
+ data.tar.gz: 4c13f38ad2c94c3fd20c537f6bed9e2bdd865ff09bc03603bf47142387fc340d5a54b5fde18eabfbd0e3a78b8b38bbab78c715f94b9073c185f903371b8e28de
data/bin/h-link CHANGED
@@ -25,6 +25,32 @@ def ensure_links_file
25
25
  File.write(LINKS_FILE, [].to_yaml) unless File.exist?(LINKS_FILE)
26
26
  end
27
27
 
28
+ def hash_matches?(links, *args)
29
+ terms = args.map(&:downcase)
30
+
31
+ links.select do |line, link|
32
+ searchable = [
33
+ link['url'],
34
+ link['description'],
35
+ link['shorthand']
36
+ ].compact.join(' ').downcase
37
+
38
+ terms.all? { |term| searchable.include?(term) }
39
+ end
40
+ end
41
+
42
+ def link_matches?(link, *args)
43
+ terms = args.map(&:downcase)
44
+
45
+ searchable = [
46
+ link['url'],
47
+ link['description'],
48
+ link['shorthand']
49
+ ].compact.join(' ').downcase
50
+
51
+ terms.all? { |term| searchable.include?(term) }
52
+ end
53
+
28
54
  def load_links
29
55
  ensure_links_file
30
56
  YAML.load_file(LINKS_FILE) || []
@@ -141,14 +167,18 @@ o.add_subcmd(:select) do |*args|
141
167
  exit 1
142
168
  end
143
169
 
144
- lines = links.each_with_index.map do |link, idx|
170
+ lines = links.each_with_index.each_with_object({}) do |(link, idx), h|
145
171
  num = (idx + 1).to_s.rjust(3)
146
172
  desc = link['description'].to_s.empty? ? "" : " - #{link['description']}"
147
- "#{num}. #{link['url']}#{desc}"
173
+ h["#{num}. #{link['url']}#{desc}"] = link
174
+ end
175
+
176
+ if args.any?
177
+ lines = hash_matches?(lines, *args)
148
178
  end
149
179
 
150
180
  require 'open3'
151
- selected, status = Open3.capture2('sk', stdin_data: lines.join("\n"))
181
+ selected, status = Open3.capture2('sk', stdin_data: lines.keys.join("\n"))
152
182
 
153
183
  if status.success? && !selected.strip.empty?
154
184
  if selected =~ /^\s*(\d+)\.\s+(\S+)/
@@ -157,6 +187,18 @@ o.add_subcmd(:select) do |*args|
157
187
  end
158
188
  end
159
189
 
190
+ o.add_subcmd(:editall) do |*args|
191
+ links_before = load_links
192
+ system(ENV['EDITOR'] || 'vim', LINKS_FILE)
193
+
194
+ begin
195
+ links_after = load_links
196
+ rescue => e
197
+ puts "ERROR: Unable to read updated file...reverting."
198
+ save_links(links_before)
199
+ end
200
+ end
201
+
160
202
  o.add_subcmd(:edit) do |*args|
161
203
  if args.empty?
162
204
  puts "Usage: h link edit <number|shorthand>"
data/lib/hiiro/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Hiiro
2
- VERSION = "0.1.13"
2
+ VERSION = "0.1.14"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hiiro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13
4
+ version: 0.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Toyota