hiiro 0.1.93 → 0.1.94
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.
- checksums.yaml +4 -4
- data/CLAUDE.md +25 -9
- data/bin/h-branch +230 -291
- data/bin/h-buffer +136 -121
- data/bin/h-commit +33 -35
- data/bin/h-link +144 -150
- data/bin/h-pane +148 -87
- data/bin/h-plugin +29 -35
- data/bin/h-pr +223 -227
- data/bin/h-project +134 -142
- data/bin/h-session +114 -60
- data/bin/h-sha +10 -13
- data/bin/h-todo +214 -215
- data/bin/h-window +124 -75
- data/bin/h-wtree +13 -14
- data/lib/hiiro/tmux/buffer.rb +63 -0
- data/lib/hiiro/tmux/buffers.rb +58 -0
- data/lib/hiiro/tmux/pane.rb +122 -0
- data/lib/hiiro/tmux/panes.rb +81 -0
- data/lib/hiiro/tmux/session.rb +86 -0
- data/lib/hiiro/tmux/sessions.rb +61 -0
- data/lib/hiiro/tmux/window.rb +94 -0
- data/lib/hiiro/tmux/windows.rb +73 -0
- data/lib/hiiro/tmux.rb +318 -0
- data/lib/hiiro/version.rb +1 -1
- data/lib/hiiro.rb +5 -0
- metadata +11 -3
- data/plugins/tmux.rb +0 -27
data/bin/h-buffer
CHANGED
|
@@ -2,126 +2,141 @@
|
|
|
2
2
|
|
|
3
3
|
require "hiiro"
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
5
|
+
Hiiro.run(*ARGV, plugins: [Pins]) do
|
|
6
|
+
tmux = tmux_client
|
|
7
|
+
|
|
8
|
+
select_buffer_proc = ->(partial = nil) {
|
|
9
|
+
buffers = tmux.buffers
|
|
10
|
+
return nil if buffers.empty?
|
|
11
|
+
|
|
12
|
+
if partial
|
|
13
|
+
buffers = buffers.matching(partial)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
return nil if buffers.empty?
|
|
17
|
+
return buffers.first.name if buffers.size == 1
|
|
18
|
+
|
|
19
|
+
fuzzyfind_from_map(buffers.name_map)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
add_subcmd(:ls) { |*args|
|
|
23
|
+
if args.empty?
|
|
24
|
+
tmux.buffers.each { |b| puts b.to_s }
|
|
25
|
+
else
|
|
26
|
+
system('tmux', 'list-buffers', *args)
|
|
27
|
+
end
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
add_subcmd(:show) { |name = nil, *args|
|
|
31
|
+
buffer_name = select_buffer_proc.call(name)
|
|
32
|
+
|
|
33
|
+
unless buffer_name
|
|
34
|
+
puts "No buffer selected or found"
|
|
35
|
+
next
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
if args.empty?
|
|
39
|
+
content = tmux.show_buffer(buffer_name)
|
|
40
|
+
print content if content
|
|
41
|
+
else
|
|
42
|
+
system('tmux', 'show-buffer', '-b', buffer_name, *args)
|
|
43
|
+
end
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
add_subcmd(:copy) { |name = nil|
|
|
47
|
+
buffer_name = select_buffer_proc.call(name)
|
|
48
|
+
unless buffer_name
|
|
49
|
+
puts "No buffer selected or found"
|
|
50
|
+
next
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
content = tmux.show_buffer(buffer_name)
|
|
54
|
+
if content
|
|
55
|
+
Hiiro::Shell.pipe(content, 'pbcopy')
|
|
56
|
+
puts "Copied buffer '#{buffer_name}' to clipboard"
|
|
57
|
+
end
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
add_subcmd(:save) { |path = nil, name = nil, *args|
|
|
61
|
+
if path.nil?
|
|
62
|
+
puts "Usage: h buffer save <path> [buffer_name]"
|
|
63
|
+
next
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
if name
|
|
67
|
+
tmux.save_buffer(path, name: name)
|
|
68
|
+
elsif args.empty?
|
|
69
|
+
buffer_name = select_buffer_proc.call(nil)
|
|
70
|
+
if buffer_name
|
|
71
|
+
tmux.save_buffer(path, name: buffer_name)
|
|
72
|
+
end
|
|
73
|
+
else
|
|
74
|
+
system('tmux', 'save-buffer', path, *args)
|
|
75
|
+
end
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
add_subcmd(:load) { |path = nil, *args|
|
|
79
|
+
if path.nil?
|
|
80
|
+
puts "Usage: h buffer load <path>"
|
|
81
|
+
next
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
if args.empty?
|
|
85
|
+
tmux.load_buffer(path)
|
|
86
|
+
else
|
|
87
|
+
system('tmux', 'load-buffer', path, *args)
|
|
88
|
+
end
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
add_subcmd(:set) { |*args|
|
|
92
|
+
system('tmux', 'set-buffer', *args)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
add_subcmd(:paste) { |name = nil, *args|
|
|
96
|
+
if name && args.empty?
|
|
97
|
+
tmux.paste_buffer(name: name)
|
|
98
|
+
elsif args.any?
|
|
99
|
+
system('tmux', 'paste-buffer', *[name && "-b", name, *args].compact)
|
|
100
|
+
else
|
|
101
|
+
tmux.paste_buffer
|
|
102
|
+
end
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
add_subcmd(:delete) { |name = nil, *args|
|
|
106
|
+
if name.nil?
|
|
107
|
+
name = select_buffer_proc.call(nil)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
if name && args.empty?
|
|
111
|
+
tmux.delete_buffer(name)
|
|
112
|
+
elsif name
|
|
113
|
+
system('tmux', 'delete-buffer', '-b', name, *args)
|
|
114
|
+
end
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
add_subcmd(:choose) { |*args|
|
|
118
|
+
if args.empty?
|
|
119
|
+
tmux.choose_buffer
|
|
120
|
+
else
|
|
121
|
+
system('tmux', 'choose-buffer', *args)
|
|
122
|
+
end
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
add_subcmd(:clear) {
|
|
126
|
+
buffers = tmux.buffers
|
|
127
|
+
count = buffers.size
|
|
128
|
+
buffers.clear_all
|
|
129
|
+
puts "Cleared #{count} buffers"
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
add_subcmd(:select) do
|
|
133
|
+
buffers = tmux.buffers
|
|
134
|
+
if buffers.empty?
|
|
135
|
+
STDERR.puts "No buffers found"
|
|
136
|
+
next
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
selected = fuzzyfind_from_map(buffers.name_map)
|
|
140
|
+
print selected if selected
|
|
19
141
|
end
|
|
20
142
|
end
|
|
21
|
-
|
|
22
|
-
def find_buffer(partial)
|
|
23
|
-
buffer_list = buffer_names
|
|
24
|
-
|
|
25
|
-
buffer, *other = buffer_list.grep(Regexp.new(partial))
|
|
26
|
-
|
|
27
|
-
return nil if other.any?
|
|
28
|
-
|
|
29
|
-
buffer
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def select_buffer(partial = nil)
|
|
33
|
-
buffers = buffer_map
|
|
34
|
-
return nil if buffers.empty?
|
|
35
|
-
|
|
36
|
-
if partial
|
|
37
|
-
buffers = buffers.select{|k,v| ![k.to_s, v.to_s].grep(Regexp.new(partial)).empty? }
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
return nil if buffers.empty?
|
|
41
|
-
return buffers.first if buffers.length == 1
|
|
42
|
-
|
|
43
|
-
Hiiro::Fuzzyfind.map_select(buffers)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
o = Hiiro.init(*ARGV, plugins: [Pins])
|
|
47
|
-
|
|
48
|
-
o.add_subcmd(:ls) { |*args|
|
|
49
|
-
system('tmux', 'list-buffers', *args)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
o.add_subcmd(:show) { |name = nil, *args|
|
|
53
|
-
buffer = select_buffer(name)
|
|
54
|
-
|
|
55
|
-
unless buffer
|
|
56
|
-
puts "No buffer selected or found"
|
|
57
|
-
next
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
print show_buffer(buffer, *args)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
o.add_subcmd(:copy) { |name = nil, *args|
|
|
64
|
-
buffer = select_buffer(name)
|
|
65
|
-
unless buffer
|
|
66
|
-
puts "No buffer selected or found"
|
|
67
|
-
next
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
content = show_buffer(buffer)
|
|
71
|
-
Hiiro::Shell.pipe(content, 'pbcopy')
|
|
72
|
-
puts "Copied buffer '#{buffer}' to clipboard"
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
o.add_subcmd(:save) { |*args|
|
|
76
|
-
system('tmux', 'save-buffer', *args)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
o.add_subcmd(:load) { |*args|
|
|
80
|
-
system('tmux', 'load-buffer', *args)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
o.add_subcmd(:set) { |*args|
|
|
84
|
-
system('tmux', 'set-buffer', *args)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
o.add_subcmd(:paste) { |*args|
|
|
88
|
-
system('tmux', 'paste-buffer', *args)
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
o.add_subcmd(:delete) { |*args|
|
|
92
|
-
system('tmux', 'delete-buffer', *args)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
o.add_subcmd(:choose) { |*args|
|
|
96
|
-
system('tmux', 'choose-buffer', *args)
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
o.add_subcmd(:clear) { |*args|
|
|
100
|
-
# Delete all buffers
|
|
101
|
-
buffers = `tmux list-buffers -F '\#{buffer_name}'`.strip.split("\n")
|
|
102
|
-
buffers.each { |buf| system('tmux', 'delete-buffer', '-b', buf) }
|
|
103
|
-
puts "Cleared #{buffers.count} buffers"
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
o.add_subcmd(:select) do |*args|
|
|
107
|
-
# Get buffer list with content preview
|
|
108
|
-
output = `tmux list-buffers -F '\#{buffer_name}: \#{buffer_sample}'`.strip
|
|
109
|
-
|
|
110
|
-
if output.empty?
|
|
111
|
-
STDERR.puts "No buffers found"
|
|
112
|
-
next
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
lines = output.split("\n").each_with_object({}) do |line, h|
|
|
116
|
-
buffer_name = line.split(':').first
|
|
117
|
-
h[line] = buffer_name
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
selected = o.fuzzyfind_from_map(lines)
|
|
121
|
-
|
|
122
|
-
if selected
|
|
123
|
-
print selected
|
|
124
|
-
end
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
o.run
|
data/bin/h-commit
CHANGED
|
@@ -2,38 +2,36 @@
|
|
|
2
2
|
|
|
3
3
|
require "hiiro"
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
hiiro.run
|
|
5
|
+
Hiiro.run(*ARGV, plugins: [Pins]) do
|
|
6
|
+
add_subcmd(:edit) { system(ENV['EDITOR'] || 'nvim', __FILE__) }
|
|
7
|
+
|
|
8
|
+
add_subcmd(:select, :sk) { |*select_args|
|
|
9
|
+
# Pass all args to git log, with sensible defaults
|
|
10
|
+
git_args = ['git', 'log', '--oneline', '--decorate', '-n', '50']
|
|
11
|
+
git_args.concat(select_args) if select_args.any?
|
|
12
|
+
|
|
13
|
+
commits = `#{git_args.shelljoin}`.lines.map(&:chomp)
|
|
14
|
+
|
|
15
|
+
if commits.empty?
|
|
16
|
+
puts "No commits found"
|
|
17
|
+
next
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
require 'open3'
|
|
21
|
+
selected, status = Open3.capture2('sk', '--no-sort', stdin_data: commits.join("\n"))
|
|
22
|
+
|
|
23
|
+
if status.success? && !selected.strip.empty?
|
|
24
|
+
# Extract just the SHA from the selected line
|
|
25
|
+
sha = selected.strip.split.first
|
|
26
|
+
puts sha
|
|
27
|
+
end
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
add_default {
|
|
31
|
+
puts "Usage: h commit <subcommand> [args]"
|
|
32
|
+
puts
|
|
33
|
+
puts "Subcommands:"
|
|
34
|
+
puts " select, sk Select a commit using sk and print its SHA"
|
|
35
|
+
puts " Additional args are passed to git log"
|
|
36
|
+
}
|
|
37
|
+
end
|
data/bin/h-link
CHANGED
|
@@ -193,213 +193,207 @@ class LinkManager
|
|
|
193
193
|
end
|
|
194
194
|
|
|
195
195
|
lm = LinkManager.new
|
|
196
|
-
o = Hiiro.init(*ARGV, plugins: [Tmux, Pins], links_file: lm.links_file)
|
|
197
196
|
|
|
198
|
-
|
|
199
|
-
|
|
197
|
+
Hiiro.run(*ARGV, plugins: [Tmux, Pins], links_file: lm.links_file) do
|
|
198
|
+
add_subcmd(:add) do |*add_args|
|
|
199
|
+
links = lm.load_links
|
|
200
200
|
|
|
201
|
-
|
|
202
|
-
|
|
201
|
+
if add_args.empty?
|
|
202
|
+
new_links = lm.edit_links
|
|
203
203
|
|
|
204
|
-
|
|
205
|
-
|
|
204
|
+
links.concat(new_links)
|
|
205
|
+
lm.save_links(links)
|
|
206
206
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
207
|
+
if new_links.length == 1
|
|
208
|
+
puts "Saved link ##{links.length}: #{new_links.first.url}"
|
|
209
|
+
else
|
|
210
|
+
puts "Saved #{new_links.length} links (#{links.length - new_links.length + 1}-#{links.length})"
|
|
211
|
+
end
|
|
212
|
+
exit 0
|
|
211
213
|
end
|
|
212
|
-
exit 0
|
|
213
|
-
end
|
|
214
214
|
|
|
215
|
-
|
|
216
|
-
|
|
215
|
+
url = add_args.shift
|
|
216
|
+
description = add_args.join(' ')
|
|
217
217
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
218
|
+
new_link = LinkManager::Link.new(
|
|
219
|
+
url: url,
|
|
220
|
+
description: description,
|
|
221
|
+
shorthand: nil,
|
|
222
|
+
created_at: Time.now.iso8601
|
|
223
|
+
)
|
|
224
224
|
|
|
225
|
-
|
|
226
|
-
|
|
225
|
+
links << new_link
|
|
226
|
+
lm.save_links(links)
|
|
227
227
|
|
|
228
|
-
|
|
229
|
-
end
|
|
228
|
+
puts "Saved link ##{links.length}: #{url}"
|
|
229
|
+
end
|
|
230
230
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
231
|
+
add_subcmd(:ls) do |*ls_args|
|
|
232
|
+
links = lm.load_links
|
|
233
|
+
if links.empty?
|
|
234
|
+
puts "No links saved."
|
|
235
|
+
else
|
|
236
|
+
links.each_with_index do |link, idx|
|
|
237
|
+
puts link.display_string(idx)
|
|
238
|
+
end
|
|
238
239
|
end
|
|
239
240
|
end
|
|
240
|
-
end
|
|
241
241
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
end
|
|
245
|
-
|
|
246
|
-
o.add_subcmd(:search) do |*args|
|
|
247
|
-
if args.empty?
|
|
248
|
-
puts "Usage: h link search <term> [term...]"
|
|
249
|
-
exit 1
|
|
242
|
+
add_subcmd(:list) do |*list_args|
|
|
243
|
+
run_subcmd(:ls, *list_args)
|
|
250
244
|
end
|
|
251
245
|
|
|
252
|
-
|
|
253
|
-
|
|
246
|
+
add_subcmd(:search) do |*search_args|
|
|
247
|
+
if search_args.empty?
|
|
248
|
+
puts "Usage: h link search <term> [term...]"
|
|
249
|
+
exit 1
|
|
250
|
+
end
|
|
254
251
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
matches.
|
|
259
|
-
puts
|
|
252
|
+
links = lm.load_links
|
|
253
|
+
matches = links.each_with_index.select { |link, idx| link.matches?(*search_args) }
|
|
254
|
+
|
|
255
|
+
if matches.empty?
|
|
256
|
+
puts "No links found matching: #{search_args.join(' ')}"
|
|
257
|
+
else
|
|
258
|
+
matches.each do |link, idx|
|
|
259
|
+
puts link.display_string(idx)
|
|
260
|
+
end
|
|
260
261
|
end
|
|
261
262
|
end
|
|
262
|
-
end
|
|
263
263
|
|
|
264
|
-
|
|
265
|
-
|
|
264
|
+
add_subcmd(:select) do |*select_args|
|
|
265
|
+
links = lm.load_links
|
|
266
266
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
267
|
+
if links.empty?
|
|
268
|
+
STDERR.puts "No links saved."
|
|
269
|
+
exit 1
|
|
270
|
+
end
|
|
271
271
|
|
|
272
|
-
|
|
272
|
+
lines = lm.load_link_hash(links)
|
|
273
273
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
274
|
+
if select_args.any?
|
|
275
|
+
lines = lm.hash_matches?(lines, *select_args)
|
|
276
|
+
end
|
|
277
277
|
|
|
278
|
-
|
|
278
|
+
selected, status = fuzzyfind(lines.keys)
|
|
279
279
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
280
|
+
if status.success? && !selected.strip.empty?
|
|
281
|
+
link = lines[selected.strip]
|
|
282
|
+
if link
|
|
283
|
+
url = link.url
|
|
284
284
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
285
|
+
if lm.has_placeholders?(url)
|
|
286
|
+
values = lm.prompt_for_placeholder_values(url, link)
|
|
287
|
+
url = lm.substitute_placeholders(url, values)
|
|
288
|
+
end
|
|
289
289
|
|
|
290
|
-
|
|
290
|
+
puts url
|
|
291
|
+
end
|
|
291
292
|
end
|
|
292
293
|
end
|
|
293
|
-
end
|
|
294
294
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
295
|
+
add_subcmd(:editall) do |*editall_args|
|
|
296
|
+
links_before = lm.load_links
|
|
297
|
+
system(ENV['EDITOR'] || 'vim', lm.links_file)
|
|
298
298
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
299
|
+
begin
|
|
300
|
+
links_after = lm.load_links
|
|
301
|
+
rescue => e
|
|
302
|
+
puts "ERROR: Unable to read updated file...reverting."
|
|
303
|
+
lm.save_links(links_before)
|
|
304
|
+
end
|
|
304
305
|
end
|
|
305
|
-
end
|
|
306
306
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
307
|
+
add_subcmd(:edit) do |*edit_args|
|
|
308
|
+
if edit_args.empty?
|
|
309
|
+
puts "Usage: h link edit <number|shorthand>"
|
|
310
|
+
exit 1
|
|
311
|
+
end
|
|
312
312
|
|
|
313
|
-
|
|
314
|
-
|
|
313
|
+
links = lm.load_links
|
|
314
|
+
idx, link = lm.find_link_by_ref(edit_args.first, links)
|
|
315
315
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
316
|
+
if link.nil?
|
|
317
|
+
puts "Link not found: #{edit_args.first}"
|
|
318
|
+
exit 1
|
|
319
|
+
end
|
|
320
320
|
|
|
321
|
-
|
|
321
|
+
updated_links = lm.edit_links(link)
|
|
322
322
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
323
|
+
# Replace the original link with the first updated link
|
|
324
|
+
# If multiple links were added, insert them all
|
|
325
|
+
links[idx] = updated_links.first
|
|
326
|
+
if updated_links.length > 1
|
|
327
|
+
links.insert(idx + 1, *updated_links[1..-1])
|
|
328
|
+
end
|
|
329
329
|
|
|
330
|
-
|
|
330
|
+
lm.save_links(links)
|
|
331
331
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
332
|
+
if updated_links.length == 1
|
|
333
|
+
puts "Updated link ##{idx + 1}"
|
|
334
|
+
else
|
|
335
|
+
puts "Updated link ##{idx + 1} and added #{updated_links.length - 1} more"
|
|
336
|
+
end
|
|
336
337
|
end
|
|
337
|
-
end
|
|
338
338
|
|
|
339
|
-
|
|
340
|
-
|
|
339
|
+
add_subcmd(:open) do |*open_args|
|
|
340
|
+
links = lm.load_links
|
|
341
341
|
|
|
342
|
-
|
|
343
|
-
|
|
342
|
+
if open_args.empty?
|
|
343
|
+
lines = lm.load_link_hash(links)
|
|
344
344
|
|
|
345
|
-
|
|
345
|
+
exit_code = 1
|
|
346
346
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
347
|
+
if open_args.any?
|
|
348
|
+
lines = lm.hash_matches?(lines, *open_args)
|
|
349
|
+
end
|
|
350
350
|
|
|
351
|
-
|
|
351
|
+
selected, status = fuzzyfind(lines.keys)
|
|
352
352
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
353
|
+
if status.success? && !selected.strip.empty?
|
|
354
|
+
link = lines[selected.strip]
|
|
355
|
+
if link
|
|
356
|
+
url = link.url
|
|
357
357
|
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
358
|
+
if lm.has_placeholders?(url)
|
|
359
|
+
values = lm.prompt_for_placeholder_values(url, link)
|
|
360
|
+
url = lm.substitute_placeholders(url, values)
|
|
361
|
+
end
|
|
362
362
|
|
|
363
|
-
|
|
364
|
-
|
|
363
|
+
system('open', url)
|
|
364
|
+
exit_code = 0
|
|
365
|
+
end
|
|
365
366
|
end
|
|
367
|
+
|
|
368
|
+
exit exit_code
|
|
366
369
|
end
|
|
367
370
|
|
|
368
|
-
|
|
369
|
-
end
|
|
371
|
+
idx, link = lm.find_link_by_ref(open_args.first, links)
|
|
370
372
|
|
|
371
|
-
|
|
373
|
+
if link.nil?
|
|
374
|
+
matches = lm.search_links(links, *open_args)
|
|
372
375
|
|
|
373
|
-
|
|
374
|
-
|
|
376
|
+
if matches.count == 1
|
|
377
|
+
link = matches.first
|
|
378
|
+
end
|
|
379
|
+
end
|
|
375
380
|
|
|
376
|
-
if
|
|
377
|
-
|
|
381
|
+
if link.nil?
|
|
382
|
+
puts "Link not found: #{open_args.first}"
|
|
383
|
+
exit 1
|
|
378
384
|
end
|
|
379
|
-
end
|
|
380
385
|
|
|
381
|
-
|
|
382
|
-
puts "Link not found: #{args.first}"
|
|
383
|
-
exit 1
|
|
384
|
-
end
|
|
386
|
+
url = link.url
|
|
385
387
|
|
|
386
|
-
|
|
388
|
+
if lm.has_placeholders?(url)
|
|
389
|
+
values = lm.prompt_for_placeholder_values(url, link)
|
|
390
|
+
url = lm.substitute_placeholders(url, values)
|
|
391
|
+
end
|
|
387
392
|
|
|
388
|
-
|
|
389
|
-
values = lm.prompt_for_placeholder_values(url, link)
|
|
390
|
-
url = lm.substitute_placeholders(url, values)
|
|
393
|
+
system('open', url)
|
|
391
394
|
end
|
|
392
395
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
o.add_subcmd(:path) do |*args|
|
|
397
|
-
print lm.links_file
|
|
398
|
-
end
|
|
399
|
-
|
|
400
|
-
begin
|
|
401
|
-
o.run
|
|
402
|
-
rescue => e
|
|
403
|
-
require 'pry'
|
|
404
|
-
binding.pry
|
|
396
|
+
add_subcmd(:path) do |*path_args|
|
|
397
|
+
print lm.links_file
|
|
398
|
+
end
|
|
405
399
|
end
|