-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.