Skip to content

Instantly share code, notes, and snippets.

@pardom-zz
Last active August 29, 2015 14:01
Show Gist options
  • Save pardom-zz/01d6cf586fca4d0aeb83 to your computer and use it in GitHub Desktop.
Save pardom-zz/01d6cf586fca4d0aeb83 to your computer and use it in GitHub Desktop.
An adb wrapper to select a device by position instead of "-s <serialNumber>"
if [ "$#" == "0" ]; then
echo "usage: adbs <device> <command>"
n=0
while read -r line
do
if [ "$n" -gt "0" ] && [ -n "$line" ]; then
echo "$n: " "$line"
else
echo "$line"
fi
n=$((n + 1))
done < <(adb devices -l)
exit 1
fi
DEVICE=$(adb devices | head -$(($1+1)) | tail -1)
ADDRESS=$(echo $DEVICE | cut -d' ' -f 1 | tr -d ' ')
shift && adb -s $ADDRESS $*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment