I typically don’t write blogs, but I have a valuab...
# random
t
I typically don’t write blogs, but I have a valuable productivity hack to share with you https://medium.com/@theapache64/adb-say-bye-to-multi-device-error-240ba10777a2
🙏 2
🔥 4
e
doesn't that break the streaming output of
adb logcat
?
t
@ephemient how come? 🤔
e
Copy code
local output=$(...)
waits until the command is finished, if it's
logcat
that's not what you want
t
@ephemient yeah… you’re right.. maybe i shud only simply check if
isMultipleDeviceConnected() && !commandHasSflag()
rather than executing the command
@ephemient
Copy code
function adb(){
	# executing actual command
	local totalLines=$(command adb devices | wc -l | xargs)
	local totalDeviceConnected=$(expr $totalLines - 2);
	if [[ "$@" != *"-s "* && $totalDeviceConnected -gt 1 ]]; then
		# Get the list of connected devices
		devices=(`command adb devices | awk '$2 == "device" {print $1}'`)
		devicesText=""
		# Loop through each device
		for device in $devices; do
			
			# Get the market name property
			market_name=$(adb -s "$device" shell getprop ro.product.vendor.marketname)
			
			# Check if market name is empty
			if [ -z "$market_name" ]; then
				# Get the model property if market name is empty
				market_name=$(adb -s "$device" shell getprop ro.product.model)
			fi
			
			devicesText+="$device - $market_name
"
		done

		local selection=$(echo $devicesText | fzf)
		local deviceId=$(echo $selection | awk '{print $1}')
		GREEN='\033[0;32m'
		NC='\033[0m' # No Color
		echo -e "Device Selected: ${GREEN}$selection${NC}"
		command adb -s $deviceId "$@"
	else
		# good to execute command
		command adb "$@"
	fi

	return;
}
e
unnecessary for commands like
adb kill-server
and there's other ways to select devices like
-d
-e
$ANDROID_SERIAL
you could simplify everything down to
Copy code
adb() {
  if command adb get-state >/dev/null 2>&1; then
    command adb "$@"
  else
    command adb -s $(command adb devices -l | awk 'NR>1&&/./' | fzf -1 | cut -d' ' -f1) "$@"
  fi
}
😍 2
👍 1