hiiro 0.1.208 → 0.1.209
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/lib/hiiro/config.rb +5 -0
- data/lib/hiiro/queue.rb +56 -13
- data/lib/hiiro/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: 682986f0fe061c64a51e17710cc46a49e7227980af6765715a0db8e896cee7d2
|
|
4
|
+
data.tar.gz: 2bc5edffca82cb8f46e1cec99c5d0d3fefd49f5a6ec9ab7f46a8c810224acdbf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8444324b5e67717a8533e1135bb54612b6ae85e0ae4e616692a6c87e715c22a6a92de79534468eb87de0c386b75fe202ad2b4f6df67c25662b7fac3229d207c3
|
|
7
|
+
data.tar.gz: 584c422ce992a137eea834db02bba83450ee8b90bb32d511057fdc55714c9a56a7edc67d6112318803e3d656cd25405306eb6a2190536fef22f795897036f074
|
data/lib/hiiro/config.rb
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
class Hiiro
|
|
2
2
|
class Config
|
|
3
3
|
BASE_DIR = File.join(Dir.home, '.config/hiiro')
|
|
4
|
+
DATA_DIR = File.join(Dir.home, '.local/share/hiiro')
|
|
4
5
|
|
|
5
6
|
class << self
|
|
6
7
|
def path(relpath='')
|
|
7
8
|
File.join(BASE_DIR, relpath)
|
|
8
9
|
end
|
|
9
10
|
|
|
11
|
+
def data_path(relpath='')
|
|
12
|
+
File.join(DATA_DIR, relpath)
|
|
13
|
+
end
|
|
14
|
+
|
|
10
15
|
def plugin_files
|
|
11
16
|
user_files = Dir.glob(File.join(plugin_dir, '*.rb'))
|
|
12
17
|
user_basenames = user_files.map { |f| File.basename(f) }
|
data/lib/hiiro/queue.rb
CHANGED
|
@@ -7,7 +7,7 @@ require 'tempfile'
|
|
|
7
7
|
|
|
8
8
|
class Hiiro
|
|
9
9
|
class Queue
|
|
10
|
-
DIR =
|
|
10
|
+
DIR = Hiiro::Config.data_path('queue')
|
|
11
11
|
TMUX_SESSION = 'hq'
|
|
12
12
|
STATUSES = %w[wip pending running done failed].freeze
|
|
13
13
|
|
|
@@ -289,6 +289,18 @@ class Hiiro
|
|
|
289
289
|
text.downcase.gsub(/[^a-z0-9]+/, '-').gsub(/^-|-$/, '')[0, 60]
|
|
290
290
|
end
|
|
291
291
|
|
|
292
|
+
# Returns [dest_path, unique_name] — appends -2, -3, etc. if a file
|
|
293
|
+
# with the same base_name already exists in dest_dir.
|
|
294
|
+
def unique_dest_path(dest_dir, base_name)
|
|
295
|
+
name = base_name
|
|
296
|
+
counter = 1
|
|
297
|
+
while File.exist?(File.join(dest_dir, "#{name}.md"))
|
|
298
|
+
counter += 1
|
|
299
|
+
name = "#{base_name}-#{counter}"
|
|
300
|
+
end
|
|
301
|
+
[File.join(dest_dir, "#{name}.md"), name]
|
|
302
|
+
end
|
|
303
|
+
|
|
292
304
|
def add_with_frontmatter(content, task_info: nil)
|
|
293
305
|
queue_dirs # ensure dirs exist
|
|
294
306
|
|
|
@@ -311,14 +323,7 @@ class Hiiro
|
|
|
311
323
|
name += '-' + task_info[:task_name] if task_info&.key?(:task_name)
|
|
312
324
|
end
|
|
313
325
|
|
|
314
|
-
|
|
315
|
-
counter = 1
|
|
316
|
-
while File.exist?(File.join(DIR, 'pending', "#{name}.md"))
|
|
317
|
-
counter += 1
|
|
318
|
-
name = "#{base_name}-#{counter}"
|
|
319
|
-
end
|
|
320
|
-
|
|
321
|
-
path = File.join(DIR, 'pending', "#{name}.md")
|
|
326
|
+
path, name = unique_dest_path(queue_dirs[:pending], name)
|
|
322
327
|
File.write(path, content + "\n")
|
|
323
328
|
{ name: name, path: path }
|
|
324
329
|
end
|
|
@@ -329,9 +334,17 @@ class Hiiro
|
|
|
329
334
|
parent_hiiro.make_child do |h|
|
|
330
335
|
h.add_subcmd(:watch) {
|
|
331
336
|
q.queue_dirs
|
|
337
|
+
current_version = Gem.loaded_specs['hiiro']&.version&.to_s
|
|
332
338
|
puts "Watching #{File.join(DIR, 'pending')} ..."
|
|
333
339
|
puts "Press Ctrl-C to stop"
|
|
334
340
|
loop do
|
|
341
|
+
if current_version
|
|
342
|
+
latest = Gem::Specification.find_by_name('hiiro')&.version&.to_s rescue nil
|
|
343
|
+
if latest && latest != current_version
|
|
344
|
+
puts "New hiiro version detected (#{latest}), restarting..."
|
|
345
|
+
exec('h', 'queue', 'watch')
|
|
346
|
+
end
|
|
347
|
+
end
|
|
335
348
|
q.tasks_in(:pending).each { |name| q.launch_task(name) }
|
|
336
349
|
sleep 2
|
|
337
350
|
end
|
|
@@ -571,9 +584,13 @@ class Hiiro
|
|
|
571
584
|
next
|
|
572
585
|
end
|
|
573
586
|
|
|
574
|
-
dst =
|
|
587
|
+
dst, dest_name = q.unique_dest_path(q.queue_dirs[:pending], name)
|
|
588
|
+
if dest_name != name
|
|
589
|
+
FileUtils.mv(src, File.join(q.queue_dirs[:wip], "#{dest_name}.md"))
|
|
590
|
+
src = File.join(q.queue_dirs[:wip], "#{dest_name}.md")
|
|
591
|
+
end
|
|
575
592
|
FileUtils.mv(src, dst)
|
|
576
|
-
puts "Moved to pending: #{
|
|
593
|
+
puts "Moved to pending: #{dest_name}"
|
|
577
594
|
}
|
|
578
595
|
|
|
579
596
|
h.add_subcmd(:kill) { |name = nil|
|
|
@@ -623,10 +640,11 @@ class Hiiro
|
|
|
623
640
|
|
|
624
641
|
dirs = q.queue_dirs
|
|
625
642
|
src_dir = dirs[found[:status].to_sym]
|
|
626
|
-
|
|
643
|
+
dst, dest_name = q.unique_dest_path(dirs[:pending], name)
|
|
644
|
+
FileUtils.mv(File.join(src_dir, "#{name}.md"), dst)
|
|
627
645
|
meta_path = File.join(src_dir, "#{name}.meta")
|
|
628
646
|
FileUtils.rm_f(meta_path) if File.exist?(meta_path)
|
|
629
|
-
puts "Moved to pending: #{
|
|
647
|
+
puts "Moved to pending: #{dest_name}"
|
|
630
648
|
}
|
|
631
649
|
|
|
632
650
|
h.add_subcmd(:clean) {
|
|
@@ -645,6 +663,31 @@ class Hiiro
|
|
|
645
663
|
q.queue_dirs
|
|
646
664
|
puts DIR
|
|
647
665
|
}
|
|
666
|
+
|
|
667
|
+
h.add_subcmd(:migrate) {
|
|
668
|
+
old_dir = File.join(Dir.home, '.config/hiiro/queue')
|
|
669
|
+
new_dir = DIR
|
|
670
|
+
|
|
671
|
+
unless Dir.exist?(old_dir)
|
|
672
|
+
puts "Nothing to migrate: #{old_dir} does not exist"
|
|
673
|
+
next
|
|
674
|
+
end
|
|
675
|
+
|
|
676
|
+
if old_dir == new_dir
|
|
677
|
+
puts "Source and destination are the same: #{old_dir}"
|
|
678
|
+
next
|
|
679
|
+
end
|
|
680
|
+
|
|
681
|
+
if Dir.exist?(new_dir) && Dir.glob(File.join(new_dir, '**', '*')).any?
|
|
682
|
+
puts "Destination already has files: #{new_dir}"
|
|
683
|
+
puts "Remove it manually if you want to migrate from #{old_dir}"
|
|
684
|
+
next
|
|
685
|
+
end
|
|
686
|
+
|
|
687
|
+
FileUtils.mkdir_p(File.dirname(new_dir))
|
|
688
|
+
FileUtils.mv(old_dir, new_dir)
|
|
689
|
+
puts "Migrated: #{old_dir} -> #{new_dir}"
|
|
690
|
+
}
|
|
648
691
|
end
|
|
649
692
|
end
|
|
650
693
|
|
data/lib/hiiro/version.rb
CHANGED