Last active
February 9, 2016 11:48
-
-
Save McPo/d788f027dfe388561e52 to your computer and use it in GitHub Desktop.
Wrapper for adb which provides an interactive device chooser.
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
#!/bin/sh | |
################# EXAMPLE USAGE ################# | |
########## TO EXECUTE A SINGLE COMMAND ########## | |
#### ./adb_c shell | |
### LAUNCH CHOOSER AND CALL MULTIPLE COMMANDS ### | |
#### . ./adb_c; targetA=$target; adb -s $targetA shell; adb -s $targetA shell pm install; echo $targetA; | |
################################################# | |
targets=($(adb devices | awk 'NR>1 {print $1}' )) | |
if [ ${#targets[@]} -eq 0 ]; then echo "No devices"; exit 0 | |
elif [ ${#targets[@]} -eq 1 ]; then target=${targets[0]} | |
else | |
echo "Select target" | |
echo ${targets[@]} | tr " " "\n" | nl -b a | |
while : ; do | |
read choice | |
((choice--)) | |
if [[ $choice -ge 0 && $choice -lt ${#targets[@]} ]]; then break; | |
else echo 'Invalid choice'; fi | |
done | |
echo "Selected ${targets[$choice]}" | |
target=${targets[$choice]} | |
fi | |
if [ ${#@} -gt 0 ]; then | |
echo "Executing adb -s $target $@" | |
adb -s $target $@ | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment