Sha256: 565b5f263f7afab9ccf349f36fb2d4514b20d2eea7c4a8f5b73f0b901ae7a89a

Contents?: true

Size: 821 Bytes

Versions: 1

Compression:

Stored size: 821 Bytes

Contents

require 'adb/peco/version'
require 'device_api/android'
require 'peco_selector'

module Adb
  module Peco
    def self.serial_option
      return nil unless adb_action
      return nil unless need_serial_option?

      devices = DeviceAPI::Android.devices
      return nil if devices.size <= 1 || devices.size == 0

      device = PecoSelector.select_from(devices.map{|device|
        ["#{device.model} (#{device.serial})", device]
      }).first
      "-s #{device.serial}"
    end

    def self.adb_action
      ARGV.reject{|a| a[0] == '-'}.first
    end

    def self.need_serial_option?
      !['help',
        'devices',
        'version',
        'start-server',
        'stop-server',
      ].include?(adb_action)
    end

    command = ['adb', serial_option, ARGV].flatten.join(' ')
    system(command)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
adb-peco-0.1.0 lib/adb/peco.rb