Last active
January 5, 2016 15:21
-
-
Save suchasplus/18670270010f14512d79 to your computer and use it in GitHub Desktop.
adb multi select
This file contains hidden or 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/bash | |
# Script adbplus | |
# Run any command adb provides on all your currently connected devices, | |
# Or prompt to select one device | |
showHelp() { | |
echo "Usage: adbplus [-a] <command>" | |
echo " -h: show help" | |
echo " -a: run command on all device" | |
echo " command: normal adb commands" | |
echo | |
echo "Examples:" | |
echo " adbplus -a install apidemo.apk" | |
echo " adbplus shell" | |
} | |
if [[ $1 = '-h' ]]; then | |
showHelp | |
exit | |
fi | |
DEVICES=() | |
while read line | |
do | |
if [ ! "$line" = "" ] && [ `echo $line | awk '{print $2}'` = "device" ] | |
then | |
device=`echo $line | awk '{print $1, $5} '` | |
DEVICES+=("${device}") | |
fi | |
done < <(adb devices -l) | |
echo "${DEVICES[@]}" | |
if [[ ${#DEVICES[@]} -lt 2 ]]; then | |
adb $@ | |
exit | |
fi | |
if [[ $1 = '-a' ]]; then | |
shift | |
for dev in "${DEVICES[@]}" | |
do | |
device=`echo $dev | awk '{print $1}'` | |
adb -s $device $@ | |
done | |
exit | |
fi | |
# select | |
PS3="Enter number to select: " | |
DEVICES+=('all') | |
select dev in "${DEVICES[@]}" | |
do | |
case "$dev" in | |
'all') | |
./$0 -a $* | |
break;; | |
*) | |
adb -s `echo $dev | awk '{print $1}'` $@ | |
break;; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment