dfd1b4f8dfe977016bfe0ecd0fc360a526252827

Author
Muhannad Fakhouri <mohand1993@hotmail.com>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

adb: improve `adb -s` completion to show helpful info (#7532)

Currently it shows for example the following:

  DEVICE_ID  -- transport_id:2

which doesn't really ease device selection. I've adapted the awk script to print
device name with it's model name, see the example below:

  DEVICE_ID  -- Pixel_3(blueline)

Diff

 1diff --git a/plugins/adb/_adb b/plugins/adb/_adb
 2index e3c20d75141d7674b6675047a94f491b0f83f5de..78c4577462cfea022527095f380ca39f0363b934 100644
 3--- a/plugins/adb/_adb
 4+++ b/plugins/adb/_adb
 5@@ -49,7 +49,12 @@ _arguments \
 6 case "$state" in
 7 	specify_device)
 8 	_values -C 'devices' ${$(adb devices -l|awk 'NR>1&& $1 \
 9-		{sub(/ +/," ",$0);gsub(":","\\:",$1); printf "%s[%s] ",$1, $NF}'):-""}
10+		{sub(/ +/," ",$0); \
11+		gsub(":","\\:",$1); \
12+		for(i=1;i<=NF;i++) {
13+			if($i ~ /model:/) { split($i,m,":") } \
14+			else if($i ~ /product:/) { split($i,p,":") } } \
15+		printf "%s[%s(%s)] ",$1, p[2], m[2]}'):-""}
16 	return
17 	;;
18 esac
19@@ -59,4 +64,4 @@ if (( CURRENT == 1 )); then
20 	return
21 fi
22 
23-_files
24+_files