Skip to content

Instantly share code, notes, and snippets.

@zmdominguez
Last active September 24, 2023 09:22
  • Star 31 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?

This script allows running an adb command (deeplinks, specifically) dynamically - i.e. ask for which device to send a command to if there are multiple devices found. Companion blog post for usage is 🔗 here.

A more flexibile version of this script (that makes it easily reusable for multiple ADB commands) is here.

2023-09-04:

  • Add instructions for explicit intents when sending the command

2023-09-21:

  • Filter out unauthorised devices
@Guaidaodl
Copy link

I use fzf to select devices, which can adapt to all adb commands. The code is very simple.

#!/usr/bin/env bash

device_count=$(($(adb devices | wc -l) - 2))

if (( device_count == 1));
then
    adb $@
elif ((device_count > 1))
then
    udid=$(adb devices -l | tail -n +2 | awk '{printf "%-20s %-8s\n", $5, $1}' | fzf | awk '{print $2}')
    echo "run adb commond in "$udid
    adb -s $udid $@
else 
    echo "no device"
fi

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