Last active
November 15, 2017 15:13
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this tries ./gradlew
../gradlew
../../gradlew
and so on, stopping at /.