From 0bd3432c5b4bfdfc89ca775fba9cc9f7db67a43f Mon Sep 17 00:00:00 2001 From: Jim Tang Date: Tue, 19 Jun 2018 19:11:48 +0800 Subject: [PATCH] Adb and fastboot completion supports zsh users. Builtin command "type" in zsh doesn't support -t option and this is resolved by checking the shell type prior to sourcing them. Instead of using "type -t" explicitly, check_type() knows the the type of the current shell and behaves accordingly. Bug: 110629292 Test: (zsh) source build/envsetup.sh && lunch aosp_arm (bash) source build/envsetup.sh && lunch aosp_arm Change-Id: Ie39e130e9cc87135cfd522abedba11ad5ac25261 --- adb/adb.bash | 10 +++++----- fastboot/fastboot.bash | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/adb/adb.bash b/adb/adb.bash index d36bec376..b1b3957c0 100644 --- a/adb/adb.bash +++ b/adb/adb.bash @@ -16,11 +16,11 @@ # _adb() { - if ! type -t "$1" >/dev/null; then + if ! check_type "$1" >/dev/null; then return fi - if type -t _init_completion >/dev/null; then + if check_type _init_completion >/dev/null; then _init_completion || return fi @@ -435,7 +435,7 @@ _adb_util_list_files() { fi # Since we're probably doing file completion here, don't add a space after. - if [[ $(type -t compopt) = "builtin" ]]; then + if [[ $(check_type compopt) == "builtin" ]]; then compopt -o nospace fi @@ -451,7 +451,7 @@ _adb_util_complete_local_file() xspec=$2 # Since we're probably doing file completion here, don't add a space after. - if [[ $(type -t compopt) = "builtin" ]]; then + if [[ $(check_type compopt) == "builtin" ]]; then compopt -o plusdirs if [[ "${xspec}" == "" ]]; then COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -f -- "${cur}") ) @@ -492,7 +492,7 @@ _adb_util_complete_local_file() } -if [[ $(type -t compopt) = "builtin" ]]; then +if [[ $(check_type compopt) == "builtin" ]]; then complete -F _adb adb else complete -o nospace -F _adb adb diff --git a/fastboot/fastboot.bash b/fastboot/fastboot.bash index dca3b4e0a..cb1d3541c 100644 --- a/fastboot/fastboot.bash +++ b/fastboot/fastboot.bash @@ -16,11 +16,11 @@ # _fastboot() { - if ! type -t "$1" >/dev/null; then + if ! check_type "$1" >/dev/null; then return fi - if type -t _init_completion >/dev/null; then + if check_type _init_completion >/dev/null; then _init_completion || return fi @@ -135,7 +135,7 @@ _fastboot_util_complete_local_file() { xspec=$2 # Since we're probably doing file completion here, don't add a space after. - if [[ $(type -t compopt) = "builtin" ]]; then + if [[ $(check_type compopt) == "builtin" ]]; then compopt -o plusdirs if [[ "${xspec}" == "" ]]; then COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -f -- "${cur}") ) @@ -175,7 +175,7 @@ _fastboot_util_complete_local_file() { fi } -if [[ $(type -t compopt) = "builtin" ]]; then +if [[ $(check_type compopt) == "builtin" ]]; then complete -F _fastboot fastboot else complete -o nospace -F _fastboot fastboot