From 7ed12083f26ce95cb9018bf6688fdba2e96514dc Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 22 Sep 2021 15:29:47 -0700 Subject: [PATCH] gradle: adopt `_bash_it_find_in_ancestor()` --- completion/available/gradle.completion.bash | 14 +++----------- plugins/available/gradle.plugin.bash | 15 +++------------ 2 files changed, 6 insertions(+), 23 deletions(-) diff --git a/completion/available/gradle.completion.bash b/completion/available/gradle.completion.bash index 786450a6..35971d50 100644 --- a/completion/available/gradle.completion.bash +++ b/completion/available/gradle.completion.bash @@ -22,17 +22,9 @@ # Avoid inaccurate completions for subproject tasks COMP_WORDBREAKS=$(echo "$COMP_WORDBREAKS" | sed -e 's/://g') -__gradle-set-project-root-dir() { - local dir="${PWD}" - project_root_dir="${PWD}" - while [[ $dir != '/' ]]; do - if [[ -f "$dir/settings.gradle" || -f "$dir/gradlew" ]]; then - project_root_dir=$dir - return 0 - fi - dir="$(dirname "$dir")" - done - return 1 +function __gradle-set-project-root-dir() { + project_root_dir="$(_bash-it-find-in-ancestor "settings.gradle" "gradlew")" + return "$?" } __gradle-init-cache-dir() { diff --git a/plugins/available/gradle.plugin.bash b/plugins/available/gradle.plugin.bash index 6267bd84..8dec1313 100644 --- a/plugins/available/gradle.plugin.bash +++ b/plugins/available/gradle.plugin.bash @@ -3,19 +3,10 @@ about-plugin 'Add a gw command to use gradle wrapper if present, else use system function gw() { local file="gradlew" - local curr_path="${PWD}" - local result="gradle" + local result - # Search recursively upwards for file. - until [[ "${curr_path}" == "/" ]]; do - if [[ -e "${curr_path}/${file}" ]]; then - result="${curr_path}/${file}" - break - else - curr_path=$(dirname "${curr_path}") - fi - done + result="$(_bash-it-find-in-ancestor "${file}")" # Call gradle - "${result}" $* + "${result:-gradle}" $* }