Skip to content

Instantly share code, notes, and snippets.

@divegeek
Forked from ncornette/gist:3272344
Last active August 29, 2015 14:26
Show Gist options
  • Save divegeek/092d1bf3a44a410d7854 to your computer and use it in GitHub Desktop.
Save divegeek/092d1bf3a44a410d7854 to your computer and use it in GitHub Desktop.
An interactive Bash function that allow you to select an Android device in a list then Sets ANDROID_SERIAL
# Display a list of all connected Android devices
# Set ANDROID_SERIAL environment from selected item
# Example of use : # adb-setdev && adb install -r myapp.apk
function adb-setdev()
{
devices=($(adb devices|grep "device$"|cut -f1))
devices_count=${#devices[*]}
if [ "$devices_count" -eq "0" ]
then
unset ANDROID_SERIAL
elif [ "$devices_count" -eq "1" ]
then
export ANDROID_SERIAL=$devices
else
# Ask for a device to select
declare -a named_devices
for device in ${devices[*]}
do
name=`adb -s $device shell ls | grep fstab | cut -f2 -d\.`
named_devices+=("${device}/${name}")
done
select named_device in ${named_devices[*]}
do
device=`echo "${named_device}" | cut -f1 -d/`
export ANDROID_SERIAL=$device
break
done
fi
}
@divegeek
Copy link
Author

divegeek commented Aug 4, 2015

This modification adds the device type to the output... at least on the devices I have handy. It looks for a file "fstab.X" and displays <device_serial>/ in the menu. This makes it easier to pick the right device if you have different types of devices and don't know all of their serial numbers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment