Skip to content

Instantly share code, notes, and snippets.

@matey-jack
Last active November 15, 2017 15:13
Show Gist options
  • Save matey-jack/603270df8cb631a0cbf5ac646b0764ab to your computer and use it in GitHub Desktop.
Save matey-jack/603270df8cb631a0cbf5ac646b0764ab to your computer and use it in GitHub Desktop.
type "gradle" in bash and run the next-closest gradlew from current working directory, falling back to globally installed one.
function gradle() {
local path=$(pwd)
while
test ! -f $path/gradlew -a / != "$path" -a -n "$path"
do
path=$(dirname $path)
done
if
test -f $path/gradlew
then
echo "Running $path/gradlew ..".
$path/gradlew $@
else
echo "No gradlew found in working dir and its parents!"
# This is not recursive, because `which` (unlike `type`) doesn't find functions.
local gradle_path=$(which gradle)
test -f "$gradle_path" && $gradle_path $@
fi
}
@matey-jack
Copy link
Author

this tries ./gradlew
../gradlew
../../gradlew
and so on, stopping at /.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment