zsh-workers
 help / color / mirror / code / Atom feed
* PATCH 1/8:  _adb: handle exec-out like shell
@ 2022-04-03 15:50 Mikael Magnusson
  2022-04-03 15:50 ` PATCH 2/8: _adb: Add dumpsys and cmd completion Mikael Magnusson
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Mikael Magnusson @ 2022-04-03 15:50 UTC (permalink / raw)
  To: zsh-workers

---
 Completion/Unix/Command/_adb | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Completion/Unix/Command/_adb b/Completion/Unix/Command/_adb
index 1375813bb2..9c0118bb72 100644
--- a/Completion/Unix/Command/_adb
+++ b/Completion/Unix/Command/_adb
@@ -43,6 +43,7 @@ _adb() {
           "disconnect"
           "emu"
           "enable-verity"
+          "exec-out"
           "forward"
           "get-devpath"
           "get-serialno"
@@ -109,7 +110,7 @@ _adb_dispatch_command () {
   fi
 
   case ${curcontext} in
-    (*:adb-shell:)
+    (*:adb-shell:|*:adb-exec-out:)
       (( $+functions[_adb_dispatch_shell] )) && _adb_dispatch_shell
       ;;
     (*:adb-backup:)
-- 
2.15.1



^ permalink raw reply	[flat|nested] 8+ messages in thread

* PATCH 2/8:  _adb: Add dumpsys and cmd completion
  2022-04-03 15:50 PATCH 1/8: _adb: handle exec-out like shell Mikael Magnusson
@ 2022-04-03 15:50 ` Mikael Magnusson
  2022-04-03 15:50 ` PATCH 3/8: _adb: Fix device serial completion for hostname:port syntax Mikael Magnusson
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Mikael Magnusson @ 2022-04-03 15:50 UTC (permalink / raw)
  To: zsh-workers

From: Mikael Magnusson <mikael.magnusson@sony.com>

---
 Completion/Unix/Command/_adb | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/Completion/Unix/Command/_adb b/Completion/Unix/Command/_adb
index 9c0118bb72..c86f9cbd0d 100644
--- a/Completion/Unix/Command/_adb
+++ b/Completion/Unix/Command/_adb
@@ -189,6 +189,12 @@ _adb_dispatch_shell () {
     (pm)
       (( $+functions[_adb_package_manager_handler] )) && _adb_package_manager_handler
       ;;
+    (cmd)
+      (( $+functions[_adb_cmd_handler] )) && _adb_cmd_handler
+      ;;
+    (dumpsys)
+      (( $+functions[_adb_dumpsys_handler] )) && _adb_dumpsys_handler
+      ;;
     (*)
       _arguments '*: :_adb_remote_folder'
       ;;
@@ -319,6 +325,20 @@ _adb_package_manager_handler () {
   esac
 }
 
+(( $+functions[_adb_cmd_handler] )) ||
+_adb_cmd_handler () {
+  local -a cmds
+  cmds=(${${${(f)"$(adb ${ADB_DEVICE_SPECIFICATION} exec-out cmd -l)"}[2,-1]}##[[:space:]]##})
+  _wanted dumpsys expl 'cmd command' compadd ${cmds%$'\r'}
+}
+
+(( $+functions[_adb_dumpsys_handler] )) ||
+_adb_dumpsys_handler () {
+  local -a services
+  services=(${${${(f)"$(adb ${ADB_DEVICE_SPECIFICATION} exec-out dumpsys -l)"}[2,-1]}##[[:space:]]##})
+  _wanted dumpsys expl 'dumpsys service' compadd ${services%$'\r'}
+}
+
 (( $+functions[_adb_dispatch_uninstall] )) ||
 _adb_dispatch_uninstall () {
   _arguments \
@@ -466,7 +486,7 @@ _adb_options_handler() {
 (( $+functions[_adb_shell_commands_handler] )) ||
 _adb_shell_commands_handler() {
   local expl
-  _wanted adb_shell_commands expl 'adb shell command' compadd ls pm am mkdir rmdir rm cat
+  _wanted adb_shell_commands expl 'adb shell command' compadd ls pm am mkdir rmdir rm cat cmd dumpsys
 }
 
 (( $+functions[_adb_device_available] )) ||
-- 
2.15.1



^ permalink raw reply	[flat|nested] 8+ messages in thread

* PATCH 3/8:  _adb: Fix device serial completion for hostname:port syntax
  2022-04-03 15:50 PATCH 1/8: _adb: handle exec-out like shell Mikael Magnusson
  2022-04-03 15:50 ` PATCH 2/8: _adb: Add dumpsys and cmd completion Mikael Magnusson
@ 2022-04-03 15:50 ` Mikael Magnusson
  2022-04-03 15:50 ` PATCH 4/8: _adb: Complete services for start/stop Mikael Magnusson
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Mikael Magnusson @ 2022-04-03 15:50 UTC (permalink / raw)
  To: zsh-workers

From: Mikael Magnusson <mikael.magnusson@sony.com>

---
 Completion/Unix/Command/_adb | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Completion/Unix/Command/_adb b/Completion/Unix/Command/_adb
index c86f9cbd0d..a429954a88 100644
--- a/Completion/Unix/Command/_adb
+++ b/Completion/Unix/Command/_adb
@@ -432,7 +432,7 @@ _adb_device_serial() {
   local expl
   local -a devices device_desc
   local device
-  devices=( $(adb devices -l | sed -n 's/^\([^[:space:]]*\)[[:space:]]*.*product:\([^[:space:]]*\).*$/\1:\2/p') )
+  devices=( $(adb devices -l | sed -n -e 's/:/\\:/' -e 's/^\([^[:space:]]*\)[[:space:]]*.*product:\([^[:space:]]*\).*$/\1:\2/p') )
   zstyle -a :completion:${curcontext} device-names device_desc
   for device in $device_desc; do
     if [[ -n $devices[(r)${device%:*}:*] ]]; then
-- 
2.15.1



^ permalink raw reply	[flat|nested] 8+ messages in thread

* PATCH 4/8:  _adb: Complete services for start/stop
  2022-04-03 15:50 PATCH 1/8: _adb: handle exec-out like shell Mikael Magnusson
  2022-04-03 15:50 ` PATCH 2/8: _adb: Add dumpsys and cmd completion Mikael Magnusson
  2022-04-03 15:50 ` PATCH 3/8: _adb: Fix device serial completion for hostname:port syntax Mikael Magnusson
@ 2022-04-03 15:50 ` Mikael Magnusson
  2022-04-03 15:50 ` PATCH 5/8: _adb: use $CURRENT instead of $#words Mikael Magnusson
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Mikael Magnusson @ 2022-04-03 15:50 UTC (permalink / raw)
  To: zsh-workers

From: Mikael Magnusson <mikael.magnusson@sony.com>

---
 Completion/Unix/Command/_adb | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/Completion/Unix/Command/_adb b/Completion/Unix/Command/_adb
index a429954a88..8d3eec5427 100644
--- a/Completion/Unix/Command/_adb
+++ b/Completion/Unix/Command/_adb
@@ -195,6 +195,9 @@ _adb_dispatch_shell () {
     (dumpsys)
       (( $+functions[_adb_dumpsys_handler] )) && _adb_dumpsys_handler
       ;;
+    (start|stop)
+      (( $+functions[_adb_startstop] )) && _adb_startstop ${words[2]}
+      ;;
     (*)
       _arguments '*: :_adb_remote_folder'
       ;;
@@ -339,6 +342,17 @@ _adb_dumpsys_handler () {
   _wanted dumpsys expl 'dumpsys service' compadd ${services%$'\r'}
 }
 
+(( $+functions[_adb_startstop] )) ||
+_adb_startstop () {
+  local -a services
+  local -A service_status
+  services=(${(f)"$(adb ${ADB_DEVICE_SPECIFICATION} exec-out getprop)"})
+  service_status=( ${(s,: ,)${(j,: ,)${(M)services:#\[init.svc.*}}} )
+  local -A map=(start stopped stop running)
+  services=( ${(k)service_status[(R)*$map[$1]*]} )
+  _wanted services expl "$map[$1] services" compadd - ${${${services#\[}%\]}#init.svc.}
+}
+
 (( $+functions[_adb_dispatch_uninstall] )) ||
 _adb_dispatch_uninstall () {
   _arguments \
@@ -486,7 +500,7 @@ _adb_options_handler() {
 (( $+functions[_adb_shell_commands_handler] )) ||
 _adb_shell_commands_handler() {
   local expl
-  _wanted adb_shell_commands expl 'adb shell command' compadd ls pm am mkdir rmdir rm cat cmd dumpsys
+  _wanted adb_shell_commands expl 'adb shell command' compadd ls pm am mkdir rmdir rm cat cmd dumpsys start stop
 }
 
 (( $+functions[_adb_device_available] )) ||
-- 
2.15.1



^ permalink raw reply	[flat|nested] 8+ messages in thread

* PATCH 5/8:  _adb: use $CURRENT instead of $#words
  2022-04-03 15:50 PATCH 1/8: _adb: handle exec-out like shell Mikael Magnusson
                   ` (2 preceding siblings ...)
  2022-04-03 15:50 ` PATCH 4/8: _adb: Complete services for start/stop Mikael Magnusson
@ 2022-04-03 15:50 ` Mikael Magnusson
  2022-04-03 15:50 ` PATCH 6/8: _adb: Parse device spec correctly Mikael Magnusson
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Mikael Magnusson @ 2022-04-03 15:50 UTC (permalink / raw)
  To: zsh-workers

From: Mikael Magnusson <mikael.magnusson@sony.com>

---
 Completion/Unix/Command/_adb | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/Completion/Unix/Command/_adb b/Completion/Unix/Command/_adb
index 8d3eec5427..b8b2470a65 100644
--- a/Completion/Unix/Command/_adb
+++ b/Completion/Unix/Command/_adb
@@ -176,7 +176,7 @@ _adb_device_specification () {
 
 (( $+functions[_adb_dispatch_shell] )) ||
 _adb_dispatch_shell () {
-  if [[ ${#words} -le 2 ]]
+  if [[ $CURRENT -le 2 ]]
   then
     (( $+functions[_adb_shell_commands_handler] )) && _adb_shell_commands_handler
     return
@@ -272,7 +272,7 @@ _adb_intent_handler () {
 
 (( $+functions[_adb_activity_manager_handler] )) ||
 _adb_activity_manager_handler () {
-  if [[ ${#words} -le 3 ]]
+  if [[ $CURRENT -le 3 ]]
   then
     _wanted am_argument expl 'am argument' compadd start startservice broadcast instrument profile
     return
@@ -379,12 +379,12 @@ _adb_dispatch_install () {
 
 (( $+functions[_adb_dispatch_push] )) ||
 _adb_dispatch_push () {
-  if [[ ${#words} -gt 3 ]] 
+  if [[ $CURRENT -gt 3 ]] 
   then
     _message -r "Notice: you can only push a single item at a time"
     return
   fi 
-  if [[ ${#words} -gt 2 ]]
+  if [[ $CURRENT -gt 2 ]]
   then
     _arguments '*: :_adb_remote_folder'
   else
@@ -394,12 +394,12 @@ _adb_dispatch_push () {
 
 (( $+functions[_adb_dispatch_pull] )) ||
 _adb_dispatch_pull () {
-  if [[ ${#words} -gt 3 ]] 
+  if [[ $CURRENT -gt 3 ]] 
   then
     _message -r "Notice: you can only pull a single item at a time"
     return
   fi 
-  if [[ ${#words} -gt 2 ]]
+  if [[ $CURRENT -gt 2 ]]
   then
     _arguments '*:local file/folder:_files'
   else
-- 
2.15.1



^ permalink raw reply	[flat|nested] 8+ messages in thread

* PATCH 6/8:  _adb: Parse device spec correctly
  2022-04-03 15:50 PATCH 1/8: _adb: handle exec-out like shell Mikael Magnusson
                   ` (3 preceding siblings ...)
  2022-04-03 15:50 ` PATCH 5/8: _adb: use $CURRENT instead of $#words Mikael Magnusson
@ 2022-04-03 15:50 ` Mikael Magnusson
  2022-04-03 15:50 ` PATCH 7/8: _adb: Handle dumpsys SurfaceFlinger arguments Mikael Magnusson
  2022-04-03 15:50 ` PATCH 8/8: _adb: also replace model names, since device names aren't sent on wifi listing Mikael Magnusson
  6 siblings, 0 replies; 8+ messages in thread
From: Mikael Magnusson @ 2022-04-03 15:50 UTC (permalink / raw)
  To: zsh-workers

From: Mikael Magnusson <mikael.magnusson@sony.com>

This was particularly annoying when trying to complete logtags after adb logcat -s
---
 Completion/Unix/Command/_adb | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/Completion/Unix/Command/_adb b/Completion/Unix/Command/_adb
index b8b2470a65..b31b84c892 100644
--- a/Completion/Unix/Command/_adb
+++ b/Completion/Unix/Command/_adb
@@ -82,6 +82,7 @@ _adb() {
   if ! adb ${ADB_DEVICE_SPECIFICATION} shell exit 2>/dev/null; then
       # early bail-out until a single valid device/emulator is specified and up-and-running
       [[ $words[CURRENT-1] = -s ]] || _message -r "No (started) device specified, completions do not yet work"
+      #TODO handle -t transport-id
       _arguments \
 	'-s[serial]: :_adb_device_serial' \
 	'(   -e)-d[device]' \
@@ -165,13 +166,11 @@ _adb_sanitize_context () {
 
 (( $+functions[_adb_device_specification] )) ||
 _adb_device_specification () {
-  local -a word
-  word=($words[(R)-[des]])
-  if [[ $words[(R)-s] == -s ]]; then
-    local i=$words[(I)-s]
-    word=($words[i,i+1])
+  if [[ $words[2] == -[de] ]]; then
+    ADB_DEVICE_SPECIFICATION=($words[2])
+  elif [[ $words[2] == -[st] ]]; then
+    ADB_DEVICE_SPECIFICATION=($words[2,3])
   fi
-  ADB_DEVICE_SPECIFICATION=($word)
 }
 
 (( $+functions[_adb_dispatch_shell] )) ||
-- 
2.15.1



^ permalink raw reply	[flat|nested] 8+ messages in thread

* PATCH 7/8:  _adb: Handle dumpsys SurfaceFlinger arguments
  2022-04-03 15:50 PATCH 1/8: _adb: handle exec-out like shell Mikael Magnusson
                   ` (4 preceding siblings ...)
  2022-04-03 15:50 ` PATCH 6/8: _adb: Parse device spec correctly Mikael Magnusson
@ 2022-04-03 15:50 ` Mikael Magnusson
  2022-04-03 15:50 ` PATCH 8/8: _adb: also replace model names, since device names aren't sent on wifi listing Mikael Magnusson
  6 siblings, 0 replies; 8+ messages in thread
From: Mikael Magnusson @ 2022-04-03 15:50 UTC (permalink / raw)
  To: zsh-workers

From: Mikael Magnusson <mikael.magnusson@sony.com>

---
 Completion/Unix/Command/_adb | 54 +++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 51 insertions(+), 3 deletions(-)

diff --git a/Completion/Unix/Command/_adb b/Completion/Unix/Command/_adb
index b31b84c892..5e7fbf8d0f 100644
--- a/Completion/Unix/Command/_adb
+++ b/Completion/Unix/Command/_adb
@@ -336,9 +336,57 @@ _adb_cmd_handler () {
 
 (( $+functions[_adb_dumpsys_handler] )) ||
 _adb_dumpsys_handler () {
-  local -a services
-  services=(${${${(f)"$(adb ${ADB_DEVICE_SPECIFICATION} exec-out dumpsys -l)"}[2,-1]}##[[:space:]]##})
-  _wanted dumpsys expl 'dumpsys service' compadd ${services%$'\r'}
+  if [[ $CURRENT -eq 3 ]]; then
+    local -a services
+    services=(${${${(f)"$(adb ${ADB_DEVICE_SPECIFICATION} exec-out dumpsys -l)"}[2,-1]}##[[:space:]]##})
+    _wanted dumpsys expl 'dumpsys service' compadd - ${services%$'\r'}
+  elif [[ $CURRENT -ge 4 && $words[3] == SurfaceFlinger ]]; then
+    (( CURRENT -= 2 ))
+    shift 2 words
+    typeset -A opt_args
+    local context state state_descr line
+    _arguments -R \
+      '--file[start/stop continuous dumpsys to file]' \
+      '--no-limit[disable wrapping around continuous dumpsys at ~20MB]' \
+      '--full-dump[set fullDump = true]' \
+      '--allocated_buffers[show allocated buffers dump]' \
+      '--display-id[show display id dump]' \
+      '--dispsync[show dispsync dump]' \
+      '--edid[raw edid dump for specified hwc display (binary output)]:*:hwc display:->hwcdisplay' \
+      '--latency[show latency stats]:*:layer:->layer' \
+      '--latency-clear[clear latency stats]:*:layer:->layer' \
+      '--list[list all layers]' \
+      '--planner[pass planner dump arguments]:*:planner arguments:->planner' \
+      '--static-screen[show static screen stats]' \
+      '--timestats[pass time stats arguments]:*:timestats arguments:->timestats' \
+      '--vsync[show vsync dump]' \
+      '--wide-color[show wide color info]' \
+      '--frametimeline[pass frametimeline arguments]:*:frametimeline arguments:->frametimeline' \
+      '--mini[show mini dump]'
+    if [[ $? == 300 ]]; then
+      case $state in
+        layer)
+          typeset -a layers
+          layers=(${${(f)"$(adb ${ADB_DEVICE_SPECIFICATION} exec-out dumpsys SurfaceFlinger --list)"}[2,-1]})
+          _wanted dumpsys expl 'layers' compadd - ${layers%$'\r'}
+          ;;
+        planner)
+          _arguments \
+            {--compare,-c}'[compare predictions of two hashes]:left: :right: :' \
+            {--describe,-d}'[describe hash]:hash: :' \
+            {--help,-h}'[help]' \
+            {--similar,-s}'[show similar stacks matching given plan]:plan: :' \
+            {--layers,-l}'[show current layers]'
+          ;;
+        timestats)
+          _arguments -disable -enable -clear -dump -maxlayers'[only with -dump]:int:'
+          ;;
+        frametimeline)
+          _arguments -jank -all
+          ;;
+      esac
+    fi
+  fi
 }
 
 (( $+functions[_adb_startstop] )) ||
-- 
2.15.1



^ permalink raw reply	[flat|nested] 8+ messages in thread

* PATCH 8/8:  _adb: also replace model names, since device names aren't sent on wifi listing
  2022-04-03 15:50 PATCH 1/8: _adb: handle exec-out like shell Mikael Magnusson
                   ` (5 preceding siblings ...)
  2022-04-03 15:50 ` PATCH 7/8: _adb: Handle dumpsys SurfaceFlinger arguments Mikael Magnusson
@ 2022-04-03 15:50 ` Mikael Magnusson
  6 siblings, 0 replies; 8+ messages in thread
From: Mikael Magnusson @ 2022-04-03 15:50 UTC (permalink / raw)
  To: zsh-workers

---
 Completion/Unix/Command/_adb | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Completion/Unix/Command/_adb b/Completion/Unix/Command/_adb
index 5e7fbf8d0f..8a071fa8ee 100644
--- a/Completion/Unix/Command/_adb
+++ b/Completion/Unix/Command/_adb
@@ -498,6 +498,8 @@ _adb_device_serial() {
   for device in $device_desc; do
     if [[ -n $devices[(r)${device%:*}:*] ]]; then
       devices[(i)${device%:*}:*]=$device
+    elif [[ -n $devices[(r)*:${device%:*}] ]]; then
+      devices[(i)*:${device%:*}]=${${devices[(r)*:${device%:*}]}%:*}:${device#*:}
     fi
   done
   _describe -t dev_serial 'available device' devices
-- 
2.15.1



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-04-03 16:08 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-03 15:50 PATCH 1/8: _adb: handle exec-out like shell Mikael Magnusson
2022-04-03 15:50 ` PATCH 2/8: _adb: Add dumpsys and cmd completion Mikael Magnusson
2022-04-03 15:50 ` PATCH 3/8: _adb: Fix device serial completion for hostname:port syntax Mikael Magnusson
2022-04-03 15:50 ` PATCH 4/8: _adb: Complete services for start/stop Mikael Magnusson
2022-04-03 15:50 ` PATCH 5/8: _adb: use $CURRENT instead of $#words Mikael Magnusson
2022-04-03 15:50 ` PATCH 6/8: _adb: Parse device spec correctly Mikael Magnusson
2022-04-03 15:50 ` PATCH 7/8: _adb: Handle dumpsys SurfaceFlinger arguments Mikael Magnusson
2022-04-03 15:50 ` PATCH 8/8: _adb: also replace model names, since device names aren't sent on wifi listing Mikael Magnusson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).