hiiro 0.1.32 → 0.1.33.pre.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 33682128f00683ee714b4bc368dbcc2243544cf3c495063231ec95497ded5bc8
4
- data.tar.gz: 8bfb329a9ec2f09a96e886c8a3ea3146ccb7a5a728ca5efc7a83509df3d578a0
3
+ metadata.gz: b2e1bf3310b631a31f3eddd49217193c44f9b7a080ca200db1524e3dbb80f8c3
4
+ data.tar.gz: efcf8d31f760fafde059592b53469189c7b21ac3a6650334e381fbf7a9a6c97a
5
5
  SHA512:
6
- metadata.gz: 6d4ad31db7afe3ca4ee5f7160e5004a086b8a5962908bc346bd30ca9a0c8a4d6948f1c699339d5103a14ea37b101b1beb8a515f17a154ec77e3b7a422cf8211e
7
- data.tar.gz: b6f2348435f48f1ba9a2ce9b38cd7a6db4d5aefca7c32d8291e96ff6faf589d061f4b2d9838fc9643ff05988dfd9489680dd684e36a478f11203ceb8b40a311d
6
+ metadata.gz: 4056150e8f6605fe2568e39e84413581edb31170bd7a93ceb8891513c94305d6a3c30bab948adbba193ae599dee6d43fe04dbeb83f3d0009795b60bb12009fa0
7
+ data.tar.gz: a8b364f3931e8597c254a1fdcd9f59442f6e9c74912985396dd2466289e43a1663edb9b92336c57115681a1a36a78ff68cc98e48ad34586db7feff1454d3a987
data/bin/g-pr CHANGED
@@ -6,8 +6,7 @@ require "fileutils"
6
6
  require "yaml"
7
7
  require "json"
8
8
 
9
- Hiiro.load_env
10
- hiiro = Hiiro.init(*ARGV, plugins: [OldTask, Tmux, Pins])
9
+ hiiro = Hiiro.init(*ARGV, plugins: [:OldTask, :Tmux, :Pins])
11
10
 
12
11
  class PRManager
13
12
  attr_reader :hiiro
data/bin/h-branch CHANGED
@@ -4,8 +4,7 @@ require "hiiro"
4
4
  require "fileutils"
5
5
  require "yaml"
6
6
 
7
- Hiiro.load_env
8
- hiiro = Hiiro.init(*ARGV, plugins: [OldTask])
7
+ hiiro = Hiiro.init(*ARGV, plugins: [:OldTask])
9
8
 
10
9
  class BranchManager
11
10
  attr_reader :hiiro
data/bin/h-buffer CHANGED
@@ -12,7 +12,7 @@ def find_buffer(partial)
12
12
  buffer
13
13
  end
14
14
 
15
- o = Hiiro.init(*ARGV, plugins: [Pins])
15
+ o = Hiiro.init(*ARGV, plugins: [:Pins])
16
16
 
17
17
  o.add_subcmd(:ls) { |*args|
18
18
  system('tmux', 'list-buffers', *args)
data/bin/h-link CHANGED
@@ -193,7 +193,7 @@ 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)
196
+ o = Hiiro.init(*ARGV, plugins: [:Tmux, :Pins], links_file: lm.links_file)
197
197
 
198
198
  o.add_subcmd(:add) do |*args|
199
199
  links = lm.load_links
data/bin/h-osubtask CHANGED
@@ -7,8 +7,7 @@ require "fileutils"
7
7
  require "yaml"
8
8
  require "time"
9
9
 
10
- Hiiro.load_env
11
- hiiro = Hiiro.init(*ARGV, plugins: [Tmux, OldTask])
10
+ hiiro = Hiiro.init(*ARGV, plugins: [:Tmux, :OldTask])
12
11
 
13
12
  tasks = hiiro.task_manager
14
13
 
data/bin/h-otask CHANGED
@@ -5,7 +5,7 @@ require "fileutils"
5
5
  require "yaml"
6
6
  require "pathname"
7
7
 
8
- hiiro = Hiiro.init(*ARGV, plugins: [Tmux])
8
+ hiiro = Hiiro.init(*ARGV, plugins: [:Tmux])
9
9
 
10
10
  class TaskManager
11
11
  attr_reader :hiiro
data/bin/h-pane CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  load File.join(Dir.home, 'bin', 'h')
4
4
 
5
- o = Hiiro.init(*ARGV, plugins: [Pins])
5
+ o = Hiiro.init(*ARGV, plugins: [:Pins])
6
6
 
7
7
  o.add_subcmd(:ls) { |*args|
8
8
  system('tmux', 'list-panes', *args)
data/bin/h-plugin CHANGED
@@ -5,7 +5,7 @@ require 'json'
5
5
  require 'hiiro'
6
6
 
7
7
  BASE_DIR = File.join(Dir.home, '.config/hiiro/plugins')
8
- o = Hiiro.init(*ARGV, plugins: [Tmux, Pins], dir: BASE_DIR)
8
+ o = Hiiro.init(*ARGV, plugins: [:Tmux, :Pins], dir: BASE_DIR)
9
9
 
10
10
  def plugin_files
11
11
  Dir.glob(File.join(BASE_DIR, '**/*'))
data/bin/h-pr CHANGED
@@ -6,8 +6,7 @@ require "fileutils"
6
6
  require "yaml"
7
7
  require "json"
8
8
 
9
- Hiiro.load_env
10
- hiiro = Hiiro.init(*ARGV, plugins: [OldTask, Tmux, Pins])
9
+ hiiro = Hiiro.init(*ARGV, plugins: [:OldTask, :Tmux, :Pins])
11
10
 
12
11
  class PRManager
13
12
  attr_reader :hiiro
data/bin/h-session CHANGED
@@ -22,7 +22,7 @@ require 'rspec'
22
22
  # has (subcommand) /Users/unixsuperhero/bin/h-session:139
23
23
  # info (subcommand) /Users/unixsuperhero/bin/h-session:143
24
24
 
25
- o = Hiiro.init(*ARGV, plugins: [Pins])
25
+ o = Hiiro.init(*ARGV, plugins: [:Pins])
26
26
 
27
27
  o.add_subcmd(:ls) { |*args|
28
28
  system('tmux', 'list-sessions', *args)
data/bin/h-sha CHANGED
@@ -4,7 +4,7 @@ require 'hiiro'
4
4
 
5
5
  BASE_DIR = File.join(Dir.home, 'work/carrot')
6
6
 
7
- Hiiro.init(*ARGV, plugins: [Tmux, Pins, Project]) { |hiiro|
7
+ Hiiro.init(*ARGV, plugins: [:Tmux, :Pins, :Project]) { |hiiro|
8
8
 
9
9
  }.run
10
10
 
data/bin/h-vim CHANGED
@@ -5,7 +5,7 @@ require 'hiiro'
5
5
  BASE_DIR = CONFIG_DIR = File.join(Dir.home, '.config/nvim')
6
6
  TMUX_SESSION_NAME = 'vim'
7
7
 
8
- o = Hiiro.init(*ARGV, plugins: [Tmux, Pins, Project])
8
+ o = Hiiro.init(*ARGV, plugins: [:Tmux, :Pins, :Project])
9
9
 
10
10
  o.add_subcmd(:edit) { |*args|
11
11
  nvim = ENV['EDITOR']
data/bin/h-window CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  load File.join(Dir.home, 'bin', 'h')
4
4
 
5
- o = Hiiro.init(*ARGV, plugins: [Pins])
5
+ o = Hiiro.init(*ARGV, plugins: [:Pins])
6
6
 
7
7
  o.add_subcmd(:ls) { |*args|
8
8
  system('tmux', 'list-windows', *args)
data/exe/h CHANGED
@@ -3,7 +3,7 @@
3
3
  require "hiiro"
4
4
  require "fileutils"
5
5
 
6
- hiiro = Hiiro.init(*ARGV, cwd: Dir.pwd, plugins: [Tasks])
6
+ hiiro = Hiiro.init(*ARGV, cwd: Dir.pwd, plugins: [:Tasks])
7
7
 
8
8
  hiiro.add_subcommand(:version) { |*args|
9
9
  puts Hiiro::VERSION
@@ -0,0 +1,64 @@
1
+ class Hiiro
2
+ class Plugins
3
+ class << self
4
+ def load_plugin(name)
5
+ name_str = name.to_s
6
+ return const_get(name_str) if plugin_loaded?(name_str)
7
+
8
+ path = plugin_path(name_str)
9
+ unless path
10
+ warn "[hiiro] plugin not found: #{name_str}"
11
+ return nil
12
+ end
13
+
14
+ module_eval(File.read(path), path, 1)
15
+
16
+ unless const_defined?(name_str, false)
17
+ warn "[hiiro] plugin #{name_str} did not define expected constant"
18
+ return nil
19
+ end
20
+
21
+ @loaded_plugins ||= []
22
+ @loaded_plugins << name_str
23
+ const_get(name_str)
24
+ end
25
+
26
+ def plugin_loaded?(name_str)
27
+ (@loaded_plugins || []).include?(name_str.to_s)
28
+ end
29
+
30
+ def plugin_path(name_str)
31
+ plugin_filename = name_str.underscore + '.rb'
32
+
33
+ paths_to_check = [
34
+ File.join(Dir.home, '.config/hiiro/plugins'),
35
+ File.join(File.expand_path('../..', __FILE__), 'plugins'),
36
+ ]
37
+
38
+ paths_to_check.each do |dir|
39
+ full_path = File.join(dir, plugin_filename)
40
+ return full_path if File.exist?(full_path)
41
+ end
42
+
43
+ nil
44
+ end
45
+
46
+ def load_all
47
+ user_dir = File.join(Dir.home, '.config/hiiro/plugins')
48
+ gem_dir = File.join(File.expand_path('../..', __FILE__), 'plugins')
49
+
50
+ FileUtils.mkdir_p(user_dir) unless Dir.exist?(user_dir)
51
+
52
+ user_files = Dir.glob(File.join(user_dir, '*.rb'))
53
+ user_basenames = user_files.map { |f| File.basename(f) }
54
+
55
+ gem_files = Dir.exist?(gem_dir) ? Dir.glob(File.join(gem_dir, '*.rb')) : []
56
+ fallback_files = gem_files.reject { |f| user_basenames.include?(File.basename(f)) }
57
+
58
+ (user_files + fallback_files).each do |path|
59
+ module_eval(File.read(path), path, 1)
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
data/lib/hiiro/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Hiiro
2
- VERSION = "0.1.32"
2
+ VERSION = "0.1.33.pre.1"
3
3
  end
data/lib/hiiro.rb CHANGED
@@ -4,15 +4,29 @@ require "shellwords"
4
4
 
5
5
  require_relative "hiiro/version"
6
6
  require_relative "hiiro/history"
7
+ require_relative "hiiro/plugins"
8
+
9
+ class String
10
+ def underscore(camel_cased_word=self)
11
+ regex = /(?:(?<=([A-Za-z\d]))|\b)((?-mix:(?=a)b))(?=\b|[^a-z])/
12
+ return camel_cased_word.to_s.dup unless /[A-Z-]|::/.match?(camel_cased_word)
13
+ word = camel_cased_word.to_s.gsub("::", "/")
14
+ word.gsub!(regex) { "#{$1 && '_' }#{$2.downcase}" }
15
+ word.gsub!(/(?<=[A-Z])(?=[A-Z][a-z])|(?<=[a-z\d])(?=[A-Z])/, "_")
16
+ word.tr!("-", "_")
17
+ word.downcase!
18
+ word
19
+ end
20
+ end
7
21
 
8
22
  class Hiiro
9
23
  def self.init(*args, plugins: [], logging: false, **values, &block)
10
- load_env
24
+ load_plugins(plugins)
11
25
  args = ARGV if args.empty?
12
26
 
13
27
  new($0, *args, logging: logging, **values).tap do |hiiro|
14
28
  History.load(hiiro)
15
- hiiro.load_plugins(*plugins)
29
+ hiiro.init_plugins(*plugins)
16
30
 
17
31
  hiiro.add_subcmd(:edit, **values) { |*args|
18
32
  system(ENV['EDITOR'] || 'nvim', hiiro.bin)
@@ -28,12 +42,10 @@ class Hiiro
28
42
  hiiro.run
29
43
  end
30
44
 
31
- def self.load_env
32
- Config.plugin_files.each do |plugin_file|
33
- require plugin_file
45
+ def self.load_plugins(plugin_list)
46
+ plugin_list.each do |name|
47
+ Plugins.load_plugin(name.to_s)
34
48
  end
35
-
36
- self
37
49
  end
38
50
 
39
51
  attr_reader :bin, :bin_name, :all_args, :full_command
@@ -119,11 +131,24 @@ class Hiiro
119
131
 
120
132
  def pins = @pins ||= Pin.new(self)
121
133
 
134
+ def init_plugins(*names)
135
+ names.flatten.each do |name|
136
+ plugin_const = Hiiro::Plugins.const_get(name.to_s) rescue nil
137
+ next unless plugin_const
138
+ load_plugin(plugin_const)
139
+ end
140
+ end
141
+
122
142
  def load_plugins(*plugins)
123
143
  plugins.flatten.each { |plugin| load_plugin(plugin) }
124
144
  end
125
145
 
126
- def load_plugin(plugin_const)
146
+ def load_plugin(plugin)
147
+ plugin_const = case plugin
148
+ when Module then plugin
149
+ when String, Symbol then Hiiro::Plugins.load_plugin(plugin.to_s)
150
+ end
151
+ return unless plugin_const
127
152
  return if @loaded_plugins.include?(plugin_const)
128
153
 
129
154
  plugin_const.load(self)
@@ -180,14 +205,6 @@ class Hiiro
180
205
 
181
206
  class Config
182
207
  class << self
183
- def plugin_files
184
- Dir.glob(File.join(plugin_dir, '*'))
185
- end
186
-
187
- def plugin_dir
188
- config_dir('plugins')
189
- end
190
-
191
208
  def config_dir(subdir=nil)
192
209
  File.join(Dir.home, '.config/hiiro', *[subdir].compact).tap do |config_path|
193
210
  FileUtils.mkdir_p(config_path) unless Dir.exist?(config_path)
@@ -437,6 +454,4 @@ class Hiiro
437
454
  end
438
455
  end
439
456
  end
440
-
441
- load_env
442
457
  end
data/plugins/tasks.rb CHANGED
@@ -289,7 +289,12 @@ class TaskManager
289
289
  assignments_file = File.join(File.dirname(tasks_file), 'assignments.yml')
290
290
  if File.exist?(assignments_file)
291
291
  raw = YAML.safe_load_file(assignments_file) || {}
292
- data = { 'tasks' => raw.map { |path, name| { 'name' => name, 'tree' => path } } }
292
+ tasks = raw.map do |tree_path, task_name|
293
+ h = { 'name' => task_name, 'tree' => tree_path }
294
+ h['session'] = task_name if task_name.include?('/')
295
+ h
296
+ end
297
+ data = { 'tasks' => tasks }
293
298
  save_tasks(data)
294
299
  return data
295
300
  end
data/script/publish CHANGED
@@ -2,9 +2,24 @@
2
2
 
3
3
  require "hiiro"
4
4
 
5
- major, minor, patch = Hiiro::VERSION.split(?.)
6
-
7
- new_version = [major, minor, patch.to_i + 1].join(?.)
5
+ pre_release = ARGV.include?("-t")
6
+ parts = Hiiro::VERSION.split(?.)
7
+
8
+ if parts.length == 5 && parts[3] == "pre"
9
+ major, minor, patch, _, pre_num = parts
10
+ if pre_release
11
+ new_version = [major, minor, patch, "pre", pre_num.to_i + 1].join(?.)
12
+ else
13
+ new_version = [major, minor, patch].join(?.)
14
+ end
15
+ else
16
+ major, minor, patch = parts
17
+ if pre_release
18
+ new_version = [major, minor, patch.to_i + 1, "pre", 1].join(?.)
19
+ else
20
+ new_version = [major, minor, patch.to_i + 1].join(?.)
21
+ end
22
+ end
8
23
 
9
24
  File.open('lib/hiiro/version.rb', 'w+') do |f|
10
25
  f.puts 'class Hiiro'
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.32
4
+ version: 0.1.33.pre.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Toyota
@@ -77,6 +77,7 @@ files:
77
77
  - hiiro.gemspec
78
78
  - lib/hiiro.rb
79
79
  - lib/hiiro/history.rb
80
+ - lib/hiiro/plugins.rb
80
81
  - lib/hiiro/version.rb
81
82
  - links.backup.yml
82
83
  - notes
@@ -108,9 +109,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
109
  version: 2.7.0
109
110
  required_rubygems_version: !ruby/object:Gem::Requirement
110
111
  requirements:
111
- - - ">="
112
+ - - ">"
112
113
  - !ruby/object:Gem::Version
113
- version: '0'
114
+ version: 1.3.1
114
115
  requirements: []
115
116
  rubygems_version: 3.3.7
116
117
  signing_key: