Sha256: 112f412221b8b11da0167b7dc12f3c0b2e371227de1120e36222fd5c7c509cbb

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

module Rbnotes::Commands

  ##
  # Picks a timestamp with a picker program, like `fzf`.

  class Pick < Command

    def description             # :nodoc:
      "Pick a timestamp with a picker program"
    end

    def execute(args, conf)
      patterns = Rbnotes.utils.expand_keyword_in_args(args)
      @repo = Textrepo.init(conf)

      list = []
      Rbnotes.utils.find_notes(patterns, @repo).each { |timestamp|
        list << Rbnotes.utils.make_headline(timestamp, @repo.read(timestamp))
      }

      picker = conf[:picker]
      unless picker.nil?
        picker_opts = conf[:picker_option]
        cmds = [picker]
        cmds.concat(picker_opts.split) unless picker_opts.nil?

        require 'open3'
        result = Open3.pipeline_rw(cmds) { |stdin, stdout, _|
          stdin.puts list
          stdin.close
          stdout.read
        }
        puts result
      else
        puts list
      end
    end

    def help                    # :nodoc:
      puts <<HELP
usage:
    #{Rbnotes::NAME} pick

Pick a timestamp with a picker program, like `fzf`.  This command
refers the configuration setting of ":picker".  If no picker program
is specified, it will behave as same as "list" command.

HELP
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rbnotes-0.4.12 lib/rbnotes/commands/pick.rb