diff options
author | Makoto Onuki <omakoto@google.com> | 2015-10-01 14:18:53 -0700 |
---|---|---|
committer | Makoto Onuki <omakoto@google.com> | 2015-10-02 15:06:34 -0700 |
commit | a4f079e7ec42159623382f15553bfff319e995eb (patch) | |
tree | 0f0500505d8dc54e1edd2907bf8db405041dedfe | |
parent | aaf3469f0235842f906688023a4e11744200c011 (diff) | |
download | platform_sdk-a4f079e7ec42159623382f15553bfff319e995eb.tar.gz platform_sdk-a4f079e7ec42159623382f15553bfff319e995eb.tar.bz2 platform_sdk-a4f079e7ec42159623382f15553bfff319e995eb.zip |
Complete subcommands for dumpsys, am and pm.
Also make the ls completion work with the new ls command.
Change-Id: Ied6d7e22f063a5d214b7a11495ae302b2b0cc165
-rw-r--r-- | bash_completion/adb.bash | 116 |
1 files changed, 103 insertions, 13 deletions
diff --git a/bash_completion/adb.bash b/bash_completion/adb.bash index 397de8e4b..f5c710579 100644 --- a/bash_completion/adb.bash +++ b/bash_completion/adb.bash @@ -210,6 +210,15 @@ _adb_cmd_shell() { ls) _adb_shell_ls $serial $i ;; + dumpsys) + _adb_cmd_shell_dumpsys "$serial" $i + ;; + am) + _adb_cmd_shell_am "$serial" $i + ;; + pm) + _adb_cmd_shell_pm "$serial" $i + ;; /*) _adb_util_list_files $serial "$cur" ;; @@ -221,6 +230,81 @@ _adb_cmd_shell() { return 0 } +_adb_cmd_shell_dumpsys() { + local serial i cur + local -a args + local candidates + + unset IFS + + serial=$1 + i=$2 + + if [ "$serial" != "none" ]; then + args=(-s $serial) + fi + + if (( $i == $COMP_CWORD )) ; then + cur="${COMP_WORDS[COMP_CWORD]}" + # First line is a header, so need "1d". + candidates=$(command adb ${args[@]} shell dumpsys -l 2> /dev/null | sed -e '1d;s/^ *//' | tr -d '\r') + candidates="-l $candidates" + COMPREPLY=( $(compgen -W "$candidates" -- "$cur") ) + return 0 + fi + + COMPREPLY=( ) + return 0 +} + +_adb_cmd_shell_am() { + local serial i cur + local candidates + + unset IFS + + serial=$1 + i=$2 + + if (( $i == $COMP_CWORD )) ; then + cur="${COMP_WORDS[COMP_CWORD]}" + candidates="broadcast clear-debug-app clear-watch-heap dumpheap force-stop get-config get-inactive hang idle-maintenance instrument kill kill-all monitor package-importance profile restart screen-compat send-trim-memory set-debug-app set-inactive set-watch-heap stack start startservice start-user stopservice stop-user suppress-resize-config-changes switch-user task to-app-uri to-intent-uri to-uri" + COMPREPLY=( $(compgen -W "$candidates" -- "$cur") ) + return 0 + fi + + COMPREPLY=( ) + return 0 +} + + +_adb_cmd_shell_pm() { + local serial i cur + local candidates + + unset IFS + + serial=$1 + i=$2 + + if (( $i == $COMP_CWORD )) ; then + cur="${COMP_WORDS[COMP_CWORD]}" + candidates="-l -lf -p clear create-user default-state disable disable-until-used disable-user dump enable get-app-link get-install-location get-max-users grant hide install install-abandon install-commit install-create install-write list move-package move-primary-storage path remove-user reset-permissions revoke set-app-link set-installer set-install-location set-permission-enforced trim-caches unhide uninstall" + COMPREPLY=( $(compgen -W "$candidates" -- "$cur") ) + return 0 + fi + + if (( $i + 1 == $COMP_CWORD )) && [[ "${COMP_WORDS[COMP_CWORD -1]}" == "list" ]] ; then + cur="${COMP_WORDS[COMP_CWORD]}" + candidates="packages permission-groups permissions instrumentation features libraries users" + COMPREPLY=( $(compgen -W "$candidates" -- "$cur") ) + return 0 + fi + + COMPREPLY=( ) + return 0 +} + _adb_cmd_uninstall() { local serial i where cur packages @@ -315,19 +399,25 @@ _adb_util_list_files() { args=(-s $serial) fi - toks=( ${toks[@]-} $( - command adb ${args[@]} shell ls -dF ${file}"*" '2>' /dev/null 2> /dev/null | tr -d '\r' | { - while read -r tmp; do - filetype=${tmp%% *} - filename=${tmp:${#filetype}+1} - if [[ ${filetype:${#filetype}-1:1} == d ]]; then - printf '%s/\n' "$filename" - else - printf '%s\n' "$filename" - fi - done - } - )) + if [[ $( command adb ${args[@]} shell ls -dF / '2>/dev/null' | tr -d '\r' ) == "d /" ]] ; then + toks=( ${toks[@]-} $( + command adb ${args[@]} shell ls -dF ${file}"*" '2>' /dev/null 2> /dev/null | tr -d '\r' | { + while read -r tmp; do + filetype=${tmp%% *} + filename=${tmp:${#filetype}+1} + if [[ ${filetype:${#filetype}-1:1} == d ]]; then + printf '%s/\n' "$filename" + else + printf '%s\n' "$filename" + fi + done + } + )) + else + toks=( ${toks[@]-} $( + command adb ${args[@]} shell ls -dp ${file}"*" '2>/dev/null' 2> /dev/null | tr -d '\r' + )) + fi # Since we're probably doing file completion here, don't add a space after. if [[ $(type -t compopt) = "builtin" ]]; then |