Merge pull request #1952 from gaelicWizard/uncle
lib/helpers: new function `_bash-it-find-in-ancestor()`pull/1966/head
commit
7fb7bb9cb8
|
|
@ -22,17 +22,9 @@
|
||||||
# Avoid inaccurate completions for subproject tasks
|
# Avoid inaccurate completions for subproject tasks
|
||||||
COMP_WORDBREAKS=$(echo "$COMP_WORDBREAKS" | sed -e 's/://g')
|
COMP_WORDBREAKS=$(echo "$COMP_WORDBREAKS" | sed -e 's/://g')
|
||||||
|
|
||||||
__gradle-set-project-root-dir() {
|
function __gradle-set-project-root-dir() {
|
||||||
local dir="${PWD}"
|
project_root_dir="$(_bash-it-find-in-ancestor "settings.gradle" "gradlew")"
|
||||||
project_root_dir="${PWD}"
|
return "$?"
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
__gradle-init-cache-dir() {
|
__gradle-init-cache-dir() {
|
||||||
|
|
|
||||||
|
|
@ -849,3 +849,30 @@ then
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# `_bash-it-find-in-ancestor` uses the shell's ability to run a function in
|
||||||
|
# a subshell to simplify our search to a simple `cd ..` and `[[ -r $1 ]]`
|
||||||
|
# without any external dependencies. Let the shell do what it's good at.
|
||||||
|
function _bash-it-find-in-ancestor() (
|
||||||
|
about 'searches parents of the current directory for any of the specified file names'
|
||||||
|
group 'helpers'
|
||||||
|
param '*: names of files or folders to search for'
|
||||||
|
returns '0: prints path of closest matching ancestor directory to stdout'
|
||||||
|
returns '1: no match found'
|
||||||
|
returns '2: improper usage of shell builtin' # uncommon
|
||||||
|
example '_bash-it-find-in-ancestor .git .hg'
|
||||||
|
example '_bash-it-find-in-ancestor GNUmakefile Makefile makefile'
|
||||||
|
|
||||||
|
local kin
|
||||||
|
# To keep things simple, we do not search the root dir.
|
||||||
|
while [[ "${PWD}" != '/' ]]; do
|
||||||
|
for kin in "$@"; do
|
||||||
|
if [[ -r "${PWD}/${kin}" ]]; then
|
||||||
|
printf '%s' "${PWD}"
|
||||||
|
return "$?"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
command cd .. || return "$?"
|
||||||
|
done
|
||||||
|
return 1
|
||||||
|
)
|
||||||
|
|
|
||||||
|
|
@ -3,19 +3,10 @@ about-plugin 'Add a gw command to use gradle wrapper if present, else use system
|
||||||
|
|
||||||
function gw() {
|
function gw() {
|
||||||
local file="gradlew"
|
local file="gradlew"
|
||||||
local curr_path="${PWD}"
|
local result
|
||||||
local result="gradle"
|
|
||||||
|
|
||||||
# Search recursively upwards for file.
|
result="$(_bash-it-find-in-ancestor "${file}")"
|
||||||
until [[ "${curr_path}" == "/" ]]; do
|
|
||||||
if [[ -e "${curr_path}/${file}" ]]; then
|
|
||||||
result="${curr_path}/${file}"
|
|
||||||
break
|
|
||||||
else
|
|
||||||
curr_path=$(dirname "${curr_path}")
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# Call gradle
|
# Call gradle
|
||||||
"${result}" $*
|
"${result:-gradle}" $*
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue