diff options
Diffstat (limited to 'Completion/Unix/Command/_adb')
-rw-r--r-- | Completion/Unix/Command/_adb | 114 |
1 files changed, 99 insertions, 15 deletions
diff --git a/Completion/Unix/Command/_adb b/Completion/Unix/Command/_adb index 1375813bb..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,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]' \ @@ -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:) @@ -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 @@ -411,11 +493,13 @@ _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 device' devices @@ -465,7 +549,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 start stop } (( $+functions[_adb_device_available] )) || |