Skip to content

Instantly share code, notes, and snippets.

@zmdominguez
Last active March 3, 2024 01:15
Show Gist options
  • Save zmdominguez/1b74a2fa6bb027870362a3ca5202a8df to your computer and use it in GitHub Desktop.
Save zmdominguez/1b74a2fa6bb027870362a3ca5202a8df to your computer and use it in GitHub Desktop.

๐Ÿ’โ€โ™€๏ธ Overview

NOTE: This gist is not being maintained anymore in favour of the more flexible, more reusable version.

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.


๐Ÿ”€ Changelog

2023-09-21:

  • Filter out unauthorised devices

2023-09-04:

  • Add instructions for explicit intents when sending the command
@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