Method: HookApp#act_on

Defined in:
lib/hook/hookapp.rb

#act_on(url) ⇒ Object



294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
# File 'lib/hook/hookapp.rb', line 294

def act_on(url)
  menu_items = ['Open in default app']
  return open_linked(url) unless File.exist?(url)

  marks = get_hooks(url)
  menu_items << 'Browse file' if marks.count.positive?

  args = ['--prompt="Choose action > "',
          '--layout=reverse-list',
          '--height=60%',
          "--min-height=#{menu_items.count + 1}"]
  sel = `echo #{Shellwords.escape(menu_items.join("\n"))} | '#{fzf}' #{args.join(' ')}`.chomp
  return if sel.nil? || sel.empty?

  case sel
  when /Browse file/
    browse_linked(url)
  else
    `open '#{url}'`
  end
end