hiiro 0.1.11 → 0.1.13

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 +34 -16
  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: c231fe73a649821cd62ad3bfafaf3a1176891fb6b37fa8a95d7e3a50499553ab
4
- data.tar.gz: cc0759a2304557485168249934b108199dce624e972bd5dc4a8663cec283a60c
3
+ metadata.gz: 80d5d0cdd946b7aecc0994b6a5bb970b3857f9e0049a6f2bb2908dc7713dc325
4
+ data.tar.gz: 9238058ff310eef9ebe8595fca12c872aaf9668299d29990750a18f54d9e2f1a
5
5
  SHA512:
6
- metadata.gz: db1cb32fc6c26d31268a845569400fb833509a5289c30b481fcc6a1e6ad0857a98eb837cbb1f1e9c957f45c8132703553d5ea593f60d93ac8bb88a53256205bb
7
- data.tar.gz: 32a64ec1dc0acdbd91d2e823c20b65ebb56749b8988531e76efa7d5cd90de0e9ca918f5d1c68377b8632780f6beacf086472e13394c2b106a7f08d1a60080367
6
+ metadata.gz: 39531bfa736dd54743fef4b2a5286137ceb6d4cc9ff14b77b0c8d6217e12e1b623953f78da41acc08d56aff3b622986a326455805d0096969c315f36d69dbed5
7
+ data.tar.gz: 969631679249c0f5d8f0fc0f377536a0aafa000e0e4a3d6ce7d34e9b03ec88282f3121a725aaccbf47d3bcc1ab10cff2e43e1e022bd3de237382a57f9f8f91de
data/bin/h-link CHANGED
@@ -3,10 +3,19 @@
3
3
  require 'yaml'
4
4
  require 'fileutils'
5
5
  require 'time'
6
-
6
+ require 'pry'
7
+ require 'tempfile'
7
8
  require "hiiro"
8
9
 
9
10
  LINKS_FILE = File.join(Dir.home, '.config/hiiro/links.yml')
11
+ LINK_TEMPLATE = {
12
+ 'url' => 'http://EXAMPLE',
13
+ 'description' => '',
14
+ 'shorthand' => nil,
15
+ 'created_at' => Time.now.iso8601,
16
+ }
17
+
18
+
10
19
 
11
20
  o = Hiiro.init(*ARGV, plugins: [Tmux, Pins], links_file: LINKS_FILE)
12
21
 
@@ -21,6 +30,19 @@ def load_links
21
30
  YAML.load_file(LINKS_FILE) || []
22
31
  end
23
32
 
33
+ def edit_link(link=LINK_TEMPLATE)
34
+ tmpfile = Tempfile.new(['link-edit-', '.yml'])
35
+ tmpfile.write(link.to_yaml)
36
+ tmpfile.close
37
+
38
+ system(ENV['EDITOR'] || 'vim', tmpfile.path)
39
+
40
+ updated = YAML.load_file(tmpfile.path)
41
+ tmpfile.unlink
42
+
43
+ updated
44
+ end
45
+
24
46
  def save_links(links)
25
47
  ensure_links_file
26
48
  File.write(LINKS_FILE, links.to_yaml)
@@ -38,16 +60,20 @@ def find_link_by_ref(ref, links)
38
60
  [nil, nil]
39
61
  end
40
62
 
41
- o.add_subcmd(:save) do |*args|
63
+ o.add_subcmd(:add) do |*args|
64
+ links = load_links
65
+
42
66
  if args.empty?
43
- puts "Usage: h link save <url> [description...]"
44
- exit 1
67
+ updated = edit_link
68
+
69
+ links << updated
70
+ save_links(links)
71
+ exit 0
45
72
  end
46
73
 
47
74
  url = args.shift
48
75
  description = args.join(' ')
49
76
 
50
- links = load_links
51
77
  links << {
52
78
  'url' => url,
53
79
  'description' => description,
@@ -93,7 +119,7 @@ o.add_subcmd(:search) do |*args|
93
119
  link['shorthand']
94
120
  ].compact.join(' ').downcase
95
121
 
96
- terms.any? { |term| searchable.include?(term) }
122
+ terms.all? { |term| searchable.include?(term) }
97
123
  end
98
124
 
99
125
  if matches.empty?
@@ -126,7 +152,7 @@ o.add_subcmd(:select) do |*args|
126
152
 
127
153
  if status.success? && !selected.strip.empty?
128
154
  if selected =~ /^\s*(\d+)\.\s+(\S+)/
129
- print $2
155
+ puts $2
130
156
  end
131
157
  end
132
158
  end
@@ -145,15 +171,7 @@ o.add_subcmd(:edit) do |*args|
145
171
  exit 1
146
172
  end
147
173
 
148
- require 'tempfile'
149
- tmpfile = Tempfile.new(['link-edit-', '.yml'])
150
- tmpfile.write(link.to_yaml)
151
- tmpfile.close
152
-
153
- system(ENV['EDITOR'] || 'vim', tmpfile.path)
154
-
155
- updated = YAML.load_file(tmpfile.path)
156
- tmpfile.unlink
174
+ updated = edit_link(link)
157
175
 
158
176
  links[idx] = updated
159
177
  save_links(links)
data/lib/hiiro/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Hiiro
2
- VERSION = "0.1.11"
2
+ VERSION = "0.1.13"
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.11
4
+ version: 0.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Toyota