Permalink
Browse files

Introduced a simple utility to manage $ANDROID_SERIAL.

  • Loading branch information...
1 parent 8a94c19 commit 3f9186283c0ce0e0cb4e8f55bb6e464f9235893a @jasta committed Jun 20, 2010
Showing with 60 additions and 0 deletions.
  1. +60 −0 pickdevice.pl
View
@@ -0,0 +1,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";

0 comments on commit 3f91862

Please sign in to comment.