Skip to content

Instantly share code, notes, and snippets.

@race604
Last active August 20, 2023 09:03
Show Gist options
  • Save race604/ecee9321b7ab30d59da0 to your computer and use it in GitHub Desktop.
Save race604/ecee9321b7ab30d59da0 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Script adb+
# Run any command adb provides on all your currently connected devices,
# Or prompt to select one device
showHelp() {
echo "Usage: adb+ [-a] <command>"
echo " -h: show help"
echo " -a: run command on all device"
echo " command: normal adb commands"
echo
echo "Examples:"
echo " adb+ -a install apidemo.apk"
echo " adb+ 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
@NoahAndrews
Copy link

Can you add a license to the top of this file?

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