gradle.plugin.zsh 791 B

1234567891011121314151617181920212223242526
  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. # if gradlew found, run it instead of gradle
  16. if [[ -f "$project_root/gradlew" ]]; then
  17. echo "executing gradlew instead of gradle"
  18. "$project_root/gradlew" "$@"
  19. else
  20. command gradle "$@"
  21. fi
  22. }
  23. alias gradle=gradle-or-gradlew
  24. compdef _gradle gradle-or-gradlew