-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathpickdevice.pl
executable file
·60 lines (45 loc) · 1.35 KB
/
pickdevice.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env perl
###############################################################################
##
## Easily manipulate the value of ANDROID_SERIAL by presenting an interactive
## list of currently connected devices.
##
## Designed to be invoked by the shell as:
##
## eval $(pickdevice)
##
###############################################################################
use strict;
use Data::Dumper;
###############################################################################
my @devicesOutput = qx{adb devices};
shift(@devicesOutput) =~ m/^List of devices/i or
die "Unexpected `adb devices' output.\n";
my @devices;
my $defaultChoice;
foreach (@devicesOutput) {
chomp;
next if m/^\s*$/;
my ($serial, $desc) = split /\s+/, $_, 2;
push @devices, { serial => $serial, desc => $desc };
if (!defined($defaultChoice) && $serial !~ m/^emulator/) {
$defaultChoice = $#devices;
}
}
if (@devices == 0) {
die "No devices connected?\n";
}
if (!defined($defaultChoice)) {
$defaultChoice = 0;
}
print STDERR "Pick a device:\n";
for (0 .. $#devices) {
print STDERR "\t", $_, ". ", $devices[$_]->{serial}, "\n";
}
print STDERR "\n";
print STDERR "Which would you like for ANDROID_SERIAL? [$defaultChoice] ";
chomp (my $answer = <STDIN>);
if (length $answer == 0) {
$answer = $defaultChoice;
}
print "export ANDROID_SERIAL=", $devices[$answer]->{serial}, "\n";