Class: Hiiro
- Inherits:
-
Object
show all
- Defined in:
- lib/hiiro.rb,
lib/hiiro/db.rb,
lib/hiiro/git.rb,
lib/hiiro/bins.rb,
lib/hiiro/glob.rb,
lib/hiiro/link.rb,
lib/hiiro/tags.rb,
lib/hiiro/tmux.rb,
lib/hiiro/todo.rb,
lib/hiiro/paths.rb,
lib/hiiro/queue.rb,
lib/hiiro/rbenv.rb,
lib/hiiro/shell.rb,
lib/hiiro/tasks.rb,
lib/hiiro/branch.rb,
lib/hiiro/config.rb,
lib/hiiro/git/pr.rb,
lib/hiiro/capture.rb,
lib/hiiro/effects.rb,
lib/hiiro/matcher.rb,
lib/hiiro/options.rb,
lib/hiiro/project.rb,
lib/hiiro/version.rb,
lib/hiiro/projects.rb,
lib/hiiro/registry.rb,
lib/hiiro/registry.rb,
lib/hiiro/reminder.rb,
lib/hiiro/app_files.rb,
lib/hiiro/check_run.rb,
lib/hiiro/fuzzyfind.rb,
lib/hiiro/pane_home.rb,
lib/hiiro/pinned_pr.rb,
lib/hiiro/tmux/pane.rb,
lib/hiiro/any_struct.rb,
lib/hiiro/app_record.rb,
lib/hiiro/assignment.rb,
lib/hiiro/background.rb,
lib/hiiro/git/branch.rb,
lib/hiiro/git/remote.rb,
lib/hiiro/input_file.rb,
lib/hiiro/invocation.rb,
lib/hiiro/pin_record.rb,
lib/hiiro/tmux/panes.rb,
lib/hiiro/runner_tool.rb,
lib/hiiro/task_colors.rb,
lib/hiiro/task_record.rb,
lib/hiiro/tmux/buffer.rb,
lib/hiiro/tmux/window.rb,
lib/hiiro/git/branches.rb,
lib/hiiro/git/worktree.rb,
lib/hiiro/notification.rb,
lib/hiiro/tmux/buffers.rb,
lib/hiiro/tmux/session.rb,
lib/hiiro/tmux/windows.rb,
lib/hiiro/git/worktrees.rb,
lib/hiiro/tmux/sessions.rb,
lib/hiiro/service_manager.rb,
lib/hiiro/pinned_pr_manager.rb
Defined Under Namespace
Modules: Background, DB, Effects, TaskColors, Tasks
Classes: AnyStruct, App, AppFiles, AppRecord, Args, Assignment, Bins, Branch, Capture, CheckRun, Config, Environment, FallbackTarget, Fuzzyfind, Git, Glob, InputFile, Invocation, InvocationResolution, Link, Matcher, Notification, Options, PaneHome, Paths, PinRecord, PinnedPRManager, PinnedPr, Project, Projects, PsProcess, Queue, Rbenv, RegistryEntry, Reminder, Result, RunnerTool, Runners, ServiceManager, Shell, SparseGroups, Tag, Tags, Task, TaskManager, TaskRecord, Tmux, TodoItem, TodoManager, Tree
Constant Summary
collapse
- WORK_DIR =
File.join(Dir.home, 'work')
- REPO_PATH =
File.join(WORK_DIR, '.bare')
- PrefixMatcher =
Backward compatibility alias
Matcher
- VERSION =
"0.1.351"
Instance Attribute Summary collapse
Class Method Summary
collapse
-
.init(*oargs, plugins: [], logging: false, tasks: false, task_scope: nil, **values, &block) ⇒ Object
-
.load_env ⇒ Object
-
.options(&block) ⇒ Object
-
.run(*args, plugins: [], logging: false, tasks: false, task_scope: nil, **values, &block) ⇒ Object
Instance Method Summary
collapse
-
#add_cmd(*names, args: [], opts: [], &block) ⇒ Object
-
#add_default(**values, &handler) ⇒ Object
-
#add_flag(name, **kwargs) ⇒ Object
-
#add_option(name, **kwargs) ⇒ Object
-
#add_resolver(name, current = nil, &lookup) ⇒ Object
-
#add_subcommand(*names, opts: nil, **values, &handler) ⇒ Object
(also: #add_subcmd)
-
#attach_method(name, &block) ⇒ Object
-
#auto_tag_branch_with_task ⇒ Object
-
#auto_var_name(path, existing_vars) ⇒ Object
-
#build_location_vars(list) ⇒ Object
-
#consolidate_dirs(dirs, min_depth:) ⇒ Object
Recursively group directories under their common ancestor when that ancestor is deep enough to be a useful alias (>= min_depth components).
-
#default_subcommand ⇒ Object
-
#edit_files(*files, max_splits: 3) ⇒ Object
-
#editor ⇒ Object
-
#environment ⇒ Object
(also: #env)
-
#full_name ⇒ Object
-
#fuzzyfind(lines) ⇒ Object
-
#fuzzyfind_from_map(mapping) ⇒ Object
-
#get_value(name) ⇒ Object
-
#git ⇒ Object
-
#handle_result(result) ⇒ Object
-
#help(options = nil) ⇒ Object
-
#initialize(bin, *all_args, logging: false, tasks: false, task_scope: nil, **values) ⇒ Hiiro
constructor
-
#list_runners(list) ⇒ Object
-
#load_plugin(plugin_const) ⇒ Object
-
#load_plugins(*plugins) ⇒ Object
-
#log(message) ⇒ Object
-
#make_child(custom_subcmd = nil, custom_args = nil, **kwargs, &block) ⇒ Object
-
#md_input_file(content: nil, append: false, prefix: 'edit-') ⇒ Object
-
#open_config(file, dir: nil) ⇒ Object
-
#options ⇒ Object
-
#parsed_args ⇒ Object
-
#path_lca(a, b) ⇒ Object
-
#pins ⇒ Object
-
#queue ⇒ Object
-
#registry_pick(type = nil) ⇒ Object
Pick a registry entry by fuzzyfinder.
-
#resolve(name, ref = nil) ⇒ Object
-
#run ⇒ Object
-
#run_child(custom_subcmd = nil, custom_args = nil, **kwargs, &block) ⇒ Object
-
#run_subcommand(name, *args) ⇒ Object
(also: #run_subcmd)
-
#runnable? ⇒ Boolean
-
#runner ⇒ Object
-
#runners ⇒ Object
-
#shorten_location(loc, vars) ⇒ Object
-
#start_tmux_session(name, **opts) ⇒ Object
-
#subcommand_names ⇒ Object
-
#task_manager ⇒ Object
(also: #tm)
-
#tasks ⇒ Object
-
#tasks_enabled? ⇒ Boolean
-
#this ⇒ Object
-
#tmux_client ⇒ Object
-
#todo_manager ⇒ Object
-
#vim? ⇒ Boolean
-
#yaml_input_file(content: nil, append: false, prefix: 'edit-') ⇒ Object
Constructor Details
#initialize(bin, *all_args, logging: false, tasks: false, task_scope: nil, **values) ⇒ Hiiro
Returns a new instance of Hiiro.
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
# File 'lib/hiiro.rb', line 157
def initialize(bin, *all_args, logging: false, tasks: false, task_scope: nil, **values)
@bin = bin
@bin_name = File.basename(bin)
@all_args = all_args
@subcmd, *@args = all_args @loaded_plugins = []
@logging = logging
@tasks_enabled = tasks
@task_scope = task_scope
@global_values = values
@full_command = [
bin_name,
*all_args,
].map(&:shellescape).join(' ')
end
|
Instance Attribute Details
#all_args ⇒ Object
Returns the value of attribute all_args.
149
150
151
|
# File 'lib/hiiro.rb', line 149
def all_args
@all_args
end
|
#args ⇒ Object
Returns the value of attribute args.
150
151
152
|
# File 'lib/hiiro.rb', line 150
def args
@args
end
|
#bin ⇒ Object
Returns the value of attribute bin.
149
150
151
|
# File 'lib/hiiro.rb', line 149
def bin
@bin
end
|
#bin_name ⇒ Object
Returns the value of attribute bin_name.
149
150
151
|
# File 'lib/hiiro.rb', line 149
def bin_name
@bin_name
end
|
#full_command ⇒ Object
Returns the value of attribute full_command.
149
150
151
|
# File 'lib/hiiro.rb', line 149
def full_command
@full_command
end
|
#global_values ⇒ Object
Returns the value of attribute global_values.
153
154
155
|
# File 'lib/hiiro.rb', line 153
def global_values
@global_values
end
|
#loaded_plugins ⇒ Object
Returns the value of attribute loaded_plugins.
151
152
153
|
# File 'lib/hiiro.rb', line 151
def loaded_plugins
@loaded_plugins
end
|
#logging ⇒ Object
Returns the value of attribute logging.
152
153
154
|
# File 'lib/hiiro.rb', line 152
def logging
@logging
end
|
#opts ⇒ Object
Returns the value of attribute opts.
155
156
157
|
# File 'lib/hiiro.rb', line 155
def opts
@opts
end
|
#subcmd ⇒ Object
Returns the value of attribute subcmd.
150
151
152
|
# File 'lib/hiiro.rb', line 150
def subcmd
@subcmd
end
|
#task_scope ⇒ Object
Returns the value of attribute task_scope.
154
155
156
|
# File 'lib/hiiro.rb', line 154
def task_scope
@task_scope
end
|
Class Method Details
.init(*oargs, plugins: [], logging: false, tasks: false, task_scope: nil, **values, &block) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/hiiro.rb', line 68
def self.init(*oargs, plugins: [], logging: false, tasks: false, task_scope: nil, **values, &block)
load_env
Hiiro::DB.setup!
h_bin = values[:bin_name] || $0
h_args = oargs
h_args = ARGV if h_args.empty?
h_args = values[:args] if values.key?(:args)
begin
Hiiro::Invocation.record!(
bin: File.basename(h_bin),
subcmd: h_args.first,
args: h_args[1..]
)
rescue => e
puts " ... ERROR ... there shouldn't be any reason for this to fail...unless sqlite is broken"
binding.pry
end
new(h_bin, *h_args, logging: logging, tasks: tasks, task_scope: task_scope, **values).tap do |hiiro|
hiiro.load_plugins(plugins)
hiiro.add_subcommand(:pry) { |*args|
binding.pry
}
hiiro.add_subcmd(:edit, **values) { |*args|
hiiro.edit_files(hiiro.bin)
}
if hiiro.tasks_enabled?
hiiro.add_subcmd(:task) do |*args|
tm = TaskManager.new(hiiro, scope: :task)
Tasks.build_hiiro(hiiro, tm).run
end
hiiro.add_subcmd(:subtask) do |*args|
tm = TaskManager.new(hiiro, scope: :subtask)
Tasks.build_hiiro(hiiro, tm).run
end
end
if block
if block.arity == 1
block.call(hiiro)
else
hiiro.instance_eval(&block)
end
end
end
end
|
.load_env ⇒ Object
141
142
143
144
145
146
147
|
# File 'lib/hiiro.rb', line 141
def self.load_env
Config.plugin_files.each do |plugin_file|
require plugin_file
end
self
end
|
.options(&block) ⇒ Object
131
132
133
|
# File 'lib/hiiro.rb', line 131
def self.options(&block)
Options.setup(&block)
end
|
.run(*args, plugins: [], logging: false, tasks: false, task_scope: nil, **values, &block) ⇒ Object
135
136
137
138
139
|
# File 'lib/hiiro.rb', line 135
def self.run(*args, plugins: [], logging: false, tasks: false, task_scope: nil, **values, &block)
hiiro = init(*args, plugins:, logging:, tasks:, task_scope:, **values, &block)
hiiro.run
end
|
Instance Method Details
#add_cmd(*names, args: [], opts: [], &block) ⇒ Object
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
|
# File 'lib/hiiro.rb', line 358
def add_cmd(*names, args: [], opts: [], &block)
cmd_opts = options.select(opts)
wrapper = lambda do |*raw_args|
@opts = cmd_opts.parse(raw_args)
instance_eval(&block)
end
names.each do |name|
runners.add_subcommand(
name, wrapper,
subcmd_args: args,
subcmd_opts: cmd_opts,
**global_values
)
end
end
|
#add_default(**values, &handler) ⇒ Object
319
320
321
|
# File 'lib/hiiro.rb', line 319
def add_default(**values, &handler)
runners.add_default(handler, **global_values, **values)
end
|
#add_flag(name, **kwargs) ⇒ Object
338
339
340
|
# File 'lib/hiiro.rb', line 338
def add_flag(name, **kwargs)
options.flag(name, **kwargs)
end
|
#add_option(name, **kwargs) ⇒ Object
334
335
336
|
# File 'lib/hiiro.rb', line 334
def add_option(name, **kwargs)
options.option(name, **kwargs)
end
|
#add_resolver(name, current = nil, &lookup) ⇒ Object
342
343
344
345
|
# File 'lib/hiiro.rb', line 342
def add_resolver(name, current = nil, &lookup)
@resolvers ||= {}
@resolvers[name.to_sym] = { current:, lookup: }
end
|
#add_subcommand(*names, opts: nil, **values, &handler) ⇒ Object
Also known as:
add_subcmd
323
324
325
326
327
|
# File 'lib/hiiro.rb', line 323
def add_subcommand(*names, opts: nil, **values, &handler)
names.each do |name|
runners.add_subcommand(name, handler, opts: opts, **global_values, **values)
end
end
|
#attach_method(name, &block) ⇒ Object
395
396
397
|
# File 'lib/hiiro.rb', line 395
def attach_method(name, &block)
define_singleton_method(name.to_sym, &block)
end
|
#auto_tag_branch_with_task ⇒ Object
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
|
# File 'lib/hiiro.rb', line 291
def auto_tag_branch_with_task
task = environment.task
return unless task
branch = environment.tree&.branch
return if branch.nil? || branch.empty?
return if %w[master main].include?(branch)
tag_store = Tags.new(:branch)
return if tag_store.get(branch).include?(task.name)
tag_store.add(branch, task.name)
rescue
end
|
#auto_var_name(path, existing_vars) ⇒ Object
517
518
519
520
521
522
523
524
|
# File 'lib/hiiro.rb', line 517
def auto_var_name(path, existing_vars)
parts = path.delete_prefix('/').split('/')
(1..parts.length).each do |n|
candidate = parts.last(n).join('_').upcase.gsub(/[^A-Z0-9]/, '_').squeeze('_').delete_prefix('_').delete_suffix('_')
return candidate unless existing_vars.key?(candidate)
end
"DIR_#{existing_vars.length + 1}"
end
|
#build_location_vars(list) ⇒ Object
480
481
482
483
484
485
486
487
488
489
490
491
492
|
# File 'lib/hiiro.rb', line 480
def build_location_vars(list)
paths = list.map { |r| r.location }.compact.map { |loc| loc.sub(/:\d+$/, '') }
dirs = paths.map { |p| File.dirname(p) }.uniq
ancestors = consolidate_dirs(dirs, min_depth: 4)
vars = {}
ancestors.sort.each do |ancestor|
name = auto_var_name(ancestor, vars)
vars[name] = ancestor
end
vars
end
|
#consolidate_dirs(dirs, min_depth:) ⇒ Object
Recursively group directories under their common ancestor when that ancestor is deep enough to be a useful alias (>= min_depth components).
496
497
498
499
500
501
502
503
504
505
506
507
508
509
|
# File 'lib/hiiro.rb', line 496
def consolidate_dirs(dirs, min_depth:)
return dirs if dirs.length <= 1
lca = dirs.reduce { |a, b| path_lca(a, b) }
lca_depth = lca.delete_prefix('/').split('/').reject(&:empty?).length
if lca_depth >= min_depth
[lca]
else
lca_parts = lca.split('/')
subgroups = dirs.group_by { |d| d.split('/').first(lca_parts.length + 1).join('/') }
subgroups.flat_map { |_, group| consolidate_dirs(group, min_depth: min_depth) }.uniq
end
end
|
#default_subcommand ⇒ Object
556
557
558
559
560
561
562
|
# File 'lib/hiiro.rb', line 556
def default_subcommand
Runners::Subcommand.new(
bin_name,
:DEFAULT,
lambda { |*args| help; false },
)
end
|
#edit_files(*files, max_splits: 3) ⇒ Object
214
215
216
217
218
219
220
221
222
223
224
|
# File 'lib/hiiro.rb', line 214
def edit_files(*files, max_splits: 3)
if editor.match?(/vim/i)
if files.count > max_splits.to_i
system(editor, '-O' + max_splits.to_i.to_s, *files)
else
system(editor, '-O', *files)
end
else
system(editor, *files)
end
end
|
#editor ⇒ Object
196
197
198
199
200
|
# File 'lib/hiiro.rb', line 196
def editor
editors = Bins.glob(%w[nvim vim vi]).find(&File.method(:executable?))
ENV['EDITOR'] || editors.first
end
|
#environment ⇒ Object
Also known as:
env
181
182
183
|
# File 'lib/hiiro.rb', line 181
def environment
@environment ||= Environment.current
end
|
#full_name ⇒ Object
381
382
383
|
# File 'lib/hiiro.rb', line 381
def full_name
runner&.full_name || [bin_name, subcmd].join(?-)
end
|
#fuzzyfind(lines) ⇒ Object
544
545
546
|
# File 'lib/hiiro.rb', line 544
def fuzzyfind(lines)
Fuzzyfind.select(lines)
end
|
#fuzzyfind_from_map(mapping) ⇒ Object
548
549
550
|
# File 'lib/hiiro.rb', line 548
def fuzzyfind_from_map(mapping)
Fuzzyfind.map_select(mapping)
end
|
#get_value(name) ⇒ Object
552
553
554
|
# File 'lib/hiiro.rb', line 552
def get_value(name)
runner&.values&.[](name)
end
|
#git ⇒ Object
391
392
393
|
# File 'lib/hiiro.rb', line 391
def git
@git ||= Git.new(self, Dir.pwd)
end
|
#handle_result(result) ⇒ Object
285
286
287
288
289
|
# File 'lib/hiiro.rb', line 285
def handle_result(result)
exit 0 if result.nil? || result
exit 1
end
|
#help(options = nil) ⇒ Object
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
|
# File 'lib/hiiro.rb', line 420
def help(options=nil)
ambiguous = runners.ambiguous_matches
puts "Current command: #{bin_name}!"
if ambiguous.any?
puts "Ambiguous subcommand #{subcmd.inspect}!"
puts
puts "Did you mean one of these?"
list_runners(ambiguous)
puts
else
puts "Subcommand required for #{bin_name}"
puts
puts "Possible subcommands:"
list_runners(runners.all_runners)
puts
end
global = @options
if global && global.definitions.any? { |k, _| k != :help }
puts "Options:"
puts global.help_text
puts
end
if options
puts "Options:"
puts options.help_text
puts
end
exit 1
end
|
#list_runners(list) ⇒ Object
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
|
# File 'lib/hiiro.rb', line 455
def list_runners(list)
sorted = list.sort_by(&:subcommand_name)
vars = build_location_vars(sorted)
vars.each { |var_name, path| puts "export #{var_name}=\"#{path}\"" }
puts if vars.any?
max_name = sorted.map { |r| r.subcommand_name.length }.max || 0
max_type = sorted.map { |r| r.type.to_s.length }.max || 0
params_with_opts = sorted.map do |r|
parts = [r.params_string, (r.respond_to?(:opts_hint) ? r.opts_hint : nil)]
parts.compact.reject(&:empty?).join(' ')
end
max_params = params_with_opts.map(&:length).max || 0
sorted.each_with_index do |r, i|
name = r.subcommand_name.ljust(max_name)
type = "(#{r.type})".ljust(max_type + 2)
params_col = params_with_opts[i].ljust(max_params)
location = shorten_location(r.location, vars)
puts " #{name} #{params_col} #{type} #{location}"
end
end
|
#load_plugin(plugin_const) ⇒ Object
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
|
# File 'lib/hiiro.rb', line 403
def load_plugin(plugin_const)
if plugin_const.is_a?(String) || plugin_const.is_a?(Symbol)
begin
plugin_const = Kernel.const_get(plugin_const.to_sym)
rescue => e
puts "unable to load plugin: #{plugin_const}"
puts "Error message: #{e.message}"
return
end
end
return if @loaded_plugins.include?(plugin_const)
plugin_const.load(self)
@loaded_plugins.push(plugin_const)
end
|
#load_plugins(*plugins) ⇒ Object
399
400
401
|
# File 'lib/hiiro.rb', line 399
def load_plugins(*plugins)
plugins.flatten.each { |plugin| load_plugin(plugin) }
end
|
#log(message) ⇒ Object
534
535
536
537
538
|
# File 'lib/hiiro.rb', line 534
def log(message)
return unless logging
puts "[Hiiro: #{bin_name} #{(runner&.subcommand_name || subcmd).inspect}]: #{message}"
end
|
#make_child(custom_subcmd = nil, custom_args = nil, **kwargs, &block) ⇒ Object
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
|
# File 'lib/hiiro.rb', line 238
def make_child(custom_subcmd=nil, custom_args=nil, **kwargs, &block)
child_subcmd = custom_subcmd || subcmd
child_args = custom_args || args
child_bin_name = [bin, child_subcmd.to_s].join(?-)
parent_resolvers = @resolvers&.dup
wrapper = lambda do |h|
h.instance_variable_set(:@resolvers, parent_resolvers.dup) if parent_resolvers
block.arity == 1 ? block.call(h) : h.instance_eval(&block) if block
end
begin
Hiiro.init(bin_name: child_bin_name, args: child_args, **kwargs, &wrapper)
rescue => e
binding.pry
end
end
|
210
211
212
|
# File 'lib/hiiro.rb', line 210
def md_input_file(content: nil, append: false, prefix: 'edit-')
InputFile.md_file(hiiro: self, content:, append:, prefix:)
end
|
#open_config(file, dir: nil) ⇒ Object
226
227
228
|
# File 'lib/hiiro.rb', line 226
def open_config(file, dir: nil)
Hiiro::Config.open(file, dir: dir)
end
|
#options ⇒ Object
330
331
332
|
# File 'lib/hiiro.rb', line 330
def options
@options ||= Hiiro::Options.setup {}
end
|
#parsed_args ⇒ Object
540
541
542
|
# File 'lib/hiiro.rb', line 540
def parsed_args
i = Args.new(*args)
end
|
#path_lca(a, b) ⇒ Object
511
512
513
514
515
|
# File 'lib/hiiro.rb', line 511
def path_lca(a, b)
a_parts = a.split('/')
b_parts = b.split('/')
a_parts.zip(b_parts).take_while { |x, y| x == y }.map(&:first).join('/')
end
|
#pins ⇒ Object
389
|
# File 'lib/hiiro.rb', line 389
def pins = @pins ||= Pin.new(self)
|
#queue ⇒ Object
266
267
268
|
# File 'lib/hiiro.rb', line 266
def queue
@queue ||= Queue.current
end
|
#registry_pick(type = nil) ⇒ Object
Pick a registry entry by fuzzyfinder. Returns the canonical name string, or nil. Usage inside a subcommand block:
task = opts.task || registry_pick('isc_task')
129
130
131
132
133
134
135
136
|
# File 'lib/hiiro/registry.rb', line 129
def registry_pick(type = nil)
lines = Hiiro::RegistryEntry.fuzzy_lines(type: type)
return nil if lines.empty?
chosen = fuzzyfind(lines)
return nil unless chosen
chosen.strip.split(/\s{2,}/)[2]
end
|
#resolve(name, ref = nil) ⇒ Object
347
348
349
350
351
352
353
354
355
356
|
# File 'lib/hiiro.rb', line 347
def resolve(name, ref = nil)
@resolvers ||= {}
r = @resolvers[name.to_sym] or raise "No resolver registered for :#{name}"
if ref.nil?
c = r[:current]
c.respond_to?(:call) ? c.call : c
else
r[:lookup]&.call(ref)
end
end
|
#run ⇒ Object
270
271
272
273
274
275
276
277
278
279
280
281
282
283
|
# File 'lib/hiiro.rb', line 270
def run
auto_tag_branch_with_task if tasks_enabled?
run_args = runners.using_default? ? [subcmd, *args].compact : args
result = runner.run(*run_args)
handle_result(result)
exit 1
rescue => e
puts "ERROR: #{e.message}"
puts e.backtrace
exit 1
end
|
#run_child(custom_subcmd = nil, custom_args = nil, **kwargs, &block) ⇒ Object
258
259
260
|
# File 'lib/hiiro.rb', line 258
def run_child(custom_subcmd=nil, custom_args=nil, **kwargs, &block)
make_child(custom_subcmd, custom_args, **kwargs, &block).run
end
|
#run_subcommand(name, *args) ⇒ Object
Also known as:
run_subcmd
376
377
378
|
# File 'lib/hiiro.rb', line 376
def run_subcommand(name, *args)
runners.run_subcommand(name, *args)
end
|
#runnable? ⇒ Boolean
307
308
309
|
# File 'lib/hiiro.rb', line 307
def runnable?
runner
end
|
#runner ⇒ Object
311
312
313
|
# File 'lib/hiiro.rb', line 311
def runner
runners.runner || runners.default_subcommand
end
|
#runners ⇒ Object
315
316
317
|
# File 'lib/hiiro.rb', line 315
def runners
@runners ||= Runners.new(self)
end
|
#shorten_location(loc, vars) ⇒ Object
526
527
528
529
530
531
532
|
# File 'lib/hiiro.rb', line 526
def shorten_location(loc, vars)
return loc if loc.nil?
vars.sort_by { |_, path| -path.length }.each do |var_name, path|
return loc.sub(path, "$#{var_name}") if loc.start_with?(path + '/') || loc == path
end
loc
end
|
#start_tmux_session(name, **opts) ⇒ Object
234
235
236
|
# File 'lib/hiiro.rb', line 234
def start_tmux_session(name, **opts)
tmux_client.open_session(name, **opts)
end
|
#subcommand_names ⇒ Object
385
386
387
|
# File 'lib/hiiro.rb', line 385
def subcommand_names
runners.subcommand_names
end
|
#task_manager ⇒ Object
Also known as:
tm
186
187
188
189
|
# File 'lib/hiiro.rb', line 186
def task_manager
return nil unless tasks_enabled?
@task_manager ||= TaskManager.new(self, scope: task_scope || :task)
end
|
#tasks ⇒ Object
192
193
194
|
# File 'lib/hiiro.rb', line 192
def tasks
task_manager&.tasks
end
|
#tasks_enabled? ⇒ Boolean
177
178
179
|
# File 'lib/hiiro.rb', line 177
def tasks_enabled?
@tasks_enabled
end
|
#this ⇒ Object
173
174
175
|
# File 'lib/hiiro.rb', line 173
def this
self
end
|
#tmux_client ⇒ Object
230
231
232
|
# File 'lib/hiiro.rb', line 230
def tmux_client
@tmux_client ||= Tmux.client!(self)
end
|
#todo_manager ⇒ Object
262
263
264
|
# File 'lib/hiiro.rb', line 262
def todo_manager
@todo_manager ||= TodoManager.new
end
|
#vim? ⇒ Boolean
202
203
204
|
# File 'lib/hiiro.rb', line 202
def vim?
editor.to_s.match?(/vim/i)
end
|
206
207
208
|
# File 'lib/hiiro.rb', line 206
def yaml_input_file(content: nil, append: false, prefix: 'edit-')
InputFile.yaml_file(hiiro: self, content:, append:, prefix:)
end
|