]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/gradle/gradle.plugin.zsh
initial
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / gradle / gradle.plugin.zsh
1 # Looks for a gradlew file in the current working directory
2 # or any of its parent directories, and executes it if found.
3 # Otherwise it will call gradle directly.
4 function gradle-or-gradlew() {
5   # find project root
6   # taken from https://github.com/gradle/gradle-completion
7   local dir="$PWD" project_root="$PWD"
8   while [[ "$dir" != / ]]; do
9     if [[ -f "$dir/settings.gradle" || -f "$dir/settings.gradle.kts" || -f "$dir/gradlew" ]]; then
10       project_root="$dir"
11       break
12     fi
13     dir="${dir:h}"
14   done
15
16   # if gradlew found, run it instead of gradle
17   if [[ -f "$project_root/gradlew" ]]; then
18     echo "executing gradlew instead of gradle"
19     "$project_root/gradlew" "$@"
20   else
21     command gradle "$@"
22   fi
23 }
24
25 alias gradle=gradle-or-gradlew
26 compdef _gradle gradle-or-gradlew