Skip to content

Instantly share code, notes, and snippets.

@linakis
Last active March 3, 2020 10:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linakis/cae4977e8181d986cff96c5aa415874c to your computer and use it in GitHub Desktop.
Save linakis/cae4977e8181d986cff96c5aa415874c to your computer and use it in GitHub Desktop.
adb device selection CLI.
clear;
echo "===============";
echo " ADB DEVICES";
echo "===============";
echo "";
adb_devices=( $(adb devices | grep -v devices | grep device | cut -f 1)#$(adb devices | grep -v devices | grep device | cut -f 2) );
if [ $((${#adb_devices[@]})) -eq "1" ] && [ "${adb_devices[0]}" == "#" ]
then
echo "No devices found";
echo "";
echo "================";
device=""
elif [ $((${#adb_devices[@]})) -eq "1" ]
then
clear
device="$(echo ${adb_devices[0]} | cut -f1 -d#)";
adb -s ${device} "$@"
else
read -p "$(
f=0
for device in "${adb_devices[@]}"; do
name="$(echo ${device} | cut -f1 -d#)";
type="$(echo ${device} | cut -f2 -d#)";
echo " $((++f)). ${name} [${type}]";
done
echo "";
echo " 0. Quit"
echo "";
echo "===============";
echo "";
echo ' Select option: '
)" selection
case "${selection}" in
0)
;;
*)
device="$(echo ${adb_devices[$((selection-1))]} | cut -f1 -d#)";
clear
echo "✔ Selected device ${device}"
echo "";
echo "adb $@"
adb -s ${device} "$@"
;;
esac
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment