Last active
July 4, 2023 17:23
-
-
Save Yash-Garg/c74a7a9a13fc63b16d352a34a3b5269b to your computer and use it in GitHub Desktop.
PowerShell Implementation for https://medium.com/@theapache64/adb-say-bye-to-multi-device-error-240ba10777a2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function a { | |
$totalLines = ((adb devices) | Measure-Object -Line).Lines | |
$devicesConnected = $totalLines - 1 | |
if ($args -notlike "*-s *" -and $devicesConnected -gt 1) { | |
$devices = ((adb devices) | Select-Object -Skip 1 | Select-Object -SkipLast 1).Split("`n") | ForEach-Object { $_.Split()[0] } | |
$devicesText = "" | |
foreach ($device in $devices) { | |
$vendor = (adb -s $device shell getprop ro.product.manufacturer).Trim() | |
$model = (adb -s $device shell getprop ro.product.model).Trim() | |
$devicesText += "$device - $model ($vendor)`n" | |
} | |
$selection = $devicesText | fzf | |
if (!$selection) { | |
return | |
} | |
$deviceId = $selection.Split()[0] | |
$Green = [ConsoleColor]::Green | |
Write-Host "Device Selected: $selection" -ForegroundColor $Green | |
adb -s $deviceId @args | |
} | |
else { | |
adb @args | |
return | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment