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.
data/bin/h-buffer CHANGED
@@ -2,126 +2,141 @@
2
2
 
3
3
  require "hiiro"
4
4
 
5
- def buffer_names
6
- `tmux list-buffers -F '\#{buffer_name}'`.strip.split("\n")
7
- end
8
-
9
- def show_buffer(name, *args)
10
- `tmux show-buffer -b #{name.shellescape} #{args.shelljoin}`
11
- end
12
-
13
- def buffer_map
14
- output = `tmux list-buffers -F '\#{buffer_name}: \#{buffer_sample}'`.strip
15
-
16
- lines = output.split("\n").each_with_object({}) do |line, h|
17
- buffer_name = line.split(': ', 2).first
18
- h[line] = buffer_name
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
- hiiro = Hiiro.init(*ARGV, plugins: [Pins])
6
-
7
- hiiro.add_subcmd(:edit) { system(ENV['EDITOR'] || 'nvim', __FILE__) }
8
-
9
- hiiro.add_subcmd(:select, :sk) { |*args|
10
- # Pass all args to git log, with sensible defaults
11
- git_args = ['git', 'log', '--oneline', '--decorate', '-n', '50']
12
- git_args.concat(args) if args.any?
13
-
14
- commits = `#{git_args.shelljoin}`.lines.map(&:chomp)
15
-
16
- if commits.empty?
17
- puts "No commits found"
18
- next
19
- end
20
-
21
- require 'open3'
22
- selected, status = Open3.capture2('sk', '--no-sort', stdin_data: commits.join("\n"))
23
-
24
- if status.success? && !selected.strip.empty?
25
- # Extract just the SHA from the selected line
26
- sha = selected.strip.split.first
27
- puts sha
28
- end
29
- }
30
-
31
- hiiro.add_default {
32
- puts "Usage: h commit <subcommand> [args]"
33
- puts
34
- puts "Subcommands:"
35
- puts " select, sk Select a commit using sk and print its SHA"
36
- puts " Additional args are passed to git log"
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
- o.add_subcmd(:add) do |*args|
199
- links = lm.load_links
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
- if args.empty?
202
- new_links = lm.edit_links
201
+ if add_args.empty?
202
+ new_links = lm.edit_links
203
203
 
204
- links.concat(new_links)
205
- lm.save_links(links)
204
+ links.concat(new_links)
205
+ lm.save_links(links)
206
206
 
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})"
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
- url = args.shift
216
- description = args.join(' ')
215
+ url = add_args.shift
216
+ description = add_args.join(' ')
217
217
 
218
- new_link = LinkManager::Link.new(
219
- url: url,
220
- description: description,
221
- shorthand: nil,
222
- created_at: Time.now.iso8601
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
- links << new_link
226
- lm.save_links(links)
225
+ links << new_link
226
+ lm.save_links(links)
227
227
 
228
- puts "Saved link ##{links.length}: #{url}"
229
- end
228
+ puts "Saved link ##{links.length}: #{url}"
229
+ end
230
230
 
231
- o.add_subcmd(:ls) do |*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)
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
- o.add_subcmd(:list) do |*args|
243
- o.run_subcmd(:ls, *args)
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
- links = lm.load_links
253
- matches = links.each_with_index.select { |link, idx| link.matches?(*args) }
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
- if matches.empty?
256
- puts "No links found matching: #{args.join(' ')}"
257
- else
258
- matches.each do |link, idx|
259
- puts link.display_string(idx)
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
- o.add_subcmd(:select) do |*args|
265
- links = lm.load_links
264
+ add_subcmd(:select) do |*select_args|
265
+ links = lm.load_links
266
266
 
267
- if links.empty?
268
- STDERR.puts "No links saved."
269
- exit 1
270
- end
267
+ if links.empty?
268
+ STDERR.puts "No links saved."
269
+ exit 1
270
+ end
271
271
 
272
- lines = lm.load_link_hash(links)
272
+ lines = lm.load_link_hash(links)
273
273
 
274
- if args.any?
275
- lines = lm.hash_matches?(lines, *args)
276
- end
274
+ if select_args.any?
275
+ lines = lm.hash_matches?(lines, *select_args)
276
+ end
277
277
 
278
- selected, status = o.fuzzyfind(lines.keys)
278
+ selected, status = fuzzyfind(lines.keys)
279
279
 
280
- if status.success? && !selected.strip.empty?
281
- link = lines[selected.strip]
282
- if link
283
- url = link.url
280
+ if status.success? && !selected.strip.empty?
281
+ link = lines[selected.strip]
282
+ if link
283
+ url = link.url
284
284
 
285
- if lm.has_placeholders?(url)
286
- values = lm.prompt_for_placeholder_values(url, link)
287
- url = lm.substitute_placeholders(url, values)
288
- end
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
- puts url
290
+ puts url
291
+ end
291
292
  end
292
293
  end
293
- end
294
294
 
295
- o.add_subcmd(:editall) do |*args|
296
- links_before = lm.load_links
297
- system(ENV['EDITOR'] || 'vim', lm.links_file)
295
+ add_subcmd(:editall) do |*editall_args|
296
+ links_before = lm.load_links
297
+ system(ENV['EDITOR'] || 'vim', lm.links_file)
298
298
 
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)
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
- o.add_subcmd(:edit) do |*args|
308
- if args.empty?
309
- puts "Usage: h link edit <number|shorthand>"
310
- exit 1
311
- end
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
- links = lm.load_links
314
- idx, link = lm.find_link_by_ref(args.first, links)
313
+ links = lm.load_links
314
+ idx, link = lm.find_link_by_ref(edit_args.first, links)
315
315
 
316
- if link.nil?
317
- puts "Link not found: #{args.first}"
318
- exit 1
319
- end
316
+ if link.nil?
317
+ puts "Link not found: #{edit_args.first}"
318
+ exit 1
319
+ end
320
320
 
321
- updated_links = lm.edit_links(link)
321
+ updated_links = lm.edit_links(link)
322
322
 
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
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
- lm.save_links(links)
330
+ lm.save_links(links)
331
331
 
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"
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
- o.add_subcmd(:open) do |*args|
340
- links = lm.load_links
339
+ add_subcmd(:open) do |*open_args|
340
+ links = lm.load_links
341
341
 
342
- if args.empty?
343
- lines = lm.load_link_hash(links)
342
+ if open_args.empty?
343
+ lines = lm.load_link_hash(links)
344
344
 
345
- exit_code = 1
345
+ exit_code = 1
346
346
 
347
- if args.any?
348
- lines = lm.hash_matches?(lines, *args)
349
- end
347
+ if open_args.any?
348
+ lines = lm.hash_matches?(lines, *open_args)
349
+ end
350
350
 
351
- selected, status = o.fuzzyfind(lines.keys)
351
+ selected, status = fuzzyfind(lines.keys)
352
352
 
353
- if status.success? && !selected.strip.empty?
354
- link = lines[selected.strip]
355
- if link
356
- url = link.url
353
+ if status.success? && !selected.strip.empty?
354
+ link = lines[selected.strip]
355
+ if link
356
+ url = link.url
357
357
 
358
- if lm.has_placeholders?(url)
359
- values = lm.prompt_for_placeholder_values(url, link)
360
- url = lm.substitute_placeholders(url, values)
361
- end
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
- system('open', url)
364
- exit_code = 0
363
+ system('open', url)
364
+ exit_code = 0
365
+ end
365
366
  end
367
+
368
+ exit exit_code
366
369
  end
367
370
 
368
- exit exit_code
369
- end
371
+ idx, link = lm.find_link_by_ref(open_args.first, links)
370
372
 
371
- idx, link = lm.find_link_by_ref(args.first, links)
373
+ if link.nil?
374
+ matches = lm.search_links(links, *open_args)
372
375
 
373
- if link.nil?
374
- matches = lm.search_links(links, *args)
376
+ if matches.count == 1
377
+ link = matches.first
378
+ end
379
+ end
375
380
 
376
- if matches.count == 1
377
- link = matches.first
381
+ if link.nil?
382
+ puts "Link not found: #{open_args.first}"
383
+ exit 1
378
384
  end
379
- end
380
385
 
381
- if link.nil?
382
- puts "Link not found: #{args.first}"
383
- exit 1
384
- end
386
+ url = link.url
385
387
 
386
- url = link.url
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
- if lm.has_placeholders?(url)
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
- system('open', url)
394
- end
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