summaryrefslogtreecommitdiff
path: root/Completion/Unix/Command/_adb
diff options
context:
space:
mode:
Diffstat (limited to 'Completion/Unix/Command/_adb')
-rw-r--r--Completion/Unix/Command/_adb130
1 files changed, 107 insertions, 23 deletions
diff --git a/Completion/Unix/Command/_adb b/Completion/Unix/Command/_adb
index 75a447dfc..8a071fa8e 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"
@@ -81,11 +82,12 @@ _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]' \
'(-d )-e[emulator]' \
- '1:options:_adb_options_handler' \
+ '1:option:_adb_options_handler' \
'*: : _default'
return
@@ -109,7 +111,7 @@ _adb_dispatch_command () {
fi
case ${curcontext} in
- (*:adb-shell:)
+ (*:adb-shell:|*:adb-exec-out:)
(( $+functions[_adb_dispatch_shell] )) && _adb_dispatch_shell
;;
(*:adb-backup:)
@@ -141,7 +143,7 @@ _adb_dispatch_command () {
'(-d -e)-s[serial]: :_adb_device_serial' \
'(-s -e)-d[device]' \
'(-d -s)-e[emulator]' \
- '*:options:_adb_options_handler'
+ '*:option:_adb_options_handler'
;;
esac
}
@@ -164,18 +166,16 @@ _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] )) ||
_adb_dispatch_shell () {
- if [[ ${#words} -le 2 ]]
+ if [[ $CURRENT -le 2 ]]
then
(( $+functions[_adb_shell_commands_handler] )) && _adb_shell_commands_handler
return
@@ -188,6 +188,15 @@ _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
+ ;;
+ (start|stop)
+ (( $+functions[_adb_startstop] )) && _adb_startstop ${words[2]}
+ ;;
(*)
_arguments '*: :_adb_remote_folder'
;;
@@ -262,7 +271,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
@@ -318,6 +327,79 @@ _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 () {
+ 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] )) ||
+_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 \
@@ -344,12 +426,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
@@ -359,12 +441,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
@@ -392,7 +474,7 @@ _adb_check_log_redirect () {
(( $+functions[_adb_trace_opts] )) ||
_adb_trace_opts() {
- _values -s , 'adb trace options' \
+ _values -s , 'adb trace option' \
'(1 adb sockets packets rwx usb sync sysdeps transport jdwp)all' \
'(all adb sockets packets rwx usb sync sysdeps transport jdwp)1' \
'adb' \
@@ -411,14 +493,16 @@ _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
devices[(i)${device%:*}:*]=$device
+ elif [[ -n $devices[(r)*:${device%:*}] ]]; then
+ devices[(i)*:${device%:*}]=${${devices[(r)*:${device%:*}]}%:*}:${device#*:}
fi
done
- _describe -t dev_serial 'available devices' devices
+ _describe -t dev_serial 'available device' devices
}
(( $+functions[_adb_logcat_filter_specification] )) ||
@@ -446,8 +530,8 @@ _adb_dispatch_logcat() {
_arguments \
'(-c -g)-s[set default filter to silent]' \
'(-c -g)-f[log output to file (defaults to stdout)]:logfile:_files' \
- '(-c -g -d)-r[rotate log every kbytes (default 16, requires -f)]:logsize:_guard "[0-9]#" "numeric value"' \
- '(-c -g -d)-n[max number of rotated logs (default 4)]:number :_guard "[0-9]#" "numeric value"' \
+ '(-c -g -d)-r[rotate log at specified size, requires -f]:log size (kbytes) [16]' \
+ '(-c -g -d)-n[specify max number of rotated logs]:number [4]' \
'(-c -g -d)-v[log format]:format: _values "format" brief process tag thread raw time threadtime long' \
'(-d -t -g)-c[clear log]' \
'(-c -g)-d[dump log]' \
@@ -459,13 +543,13 @@ _adb_dispatch_logcat() {
(( $+functions[_adb_options_handler] )) ||
_adb_options_handler() {
local expl
- _wanted adb_options expl 'adb options' compadd "${ALL_ADB_COMMANDS[@]}"
+ _wanted adb_options expl 'adb option' compadd "${ALL_ADB_COMMANDS[@]}"
}
(( $+functions[_adb_shell_commands_handler] )) ||
_adb_shell_commands_handler() {
local expl
- _wanted adb_shell_commands expl 'adb shell commands' 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 start stop
}
(( $+functions[_adb_device_available] )) ||
@@ -514,7 +598,7 @@ _adb_installed_packages() {
_adb_users() {
local -a users
users=( ${${${(M)${(f)"$(adb shell pm list users)"}:#*UserInfo*}#*UserInfo\{}%:*} )
- _describe -t users 'users' users
+ _describe -t users 'user' users
}
(( $+functions[_adb_cache_policy_single_command] )) ||