From 263934eec0edbb24f1acd729ddbc5f29b7697509 Mon Sep 17 00:00:00 2001 From: Chriptus Date: Fri, 4 Oct 2024 17:25:45 +0100 Subject: [PATCH] feat: added Gradle plugin --- plugins/README.md | 1 + plugins/gradle/README.md | 25 +++++++++++++++++++++++++ plugins/gradle/gradle.plugin.sh | 24 ++++++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 plugins/gradle/README.md create mode 100644 plugins/gradle/gradle.plugin.sh diff --git a/plugins/README.md b/plugins/README.md index a4e0df249..37099a2f4 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -41,6 +41,7 @@ By leveraging these plugins, you can streamline your workflow and tackle coding | git | Distributed version control system for managing the history of changes in software projects. | | goenv | Tool for managing Go versions within a development environment. | | golang | The Go programming language, along with its tools and standard libraries. | +| gradle | This plugin adds completions and aliases for Gradle. | | kubectl | Command-line tool for interacting with Kubernetes clusters. | | npm | Package manager for Node.js facilitating installation and management of project dependencies. | | nvm | Node.js version manager allowing easy switching between different Node.js versions. | diff --git a/plugins/gradle/README.md b/plugins/gradle/README.md new file mode 100644 index 000000000..4b93b446b --- /dev/null +++ b/plugins/gradle/README.md @@ -0,0 +1,25 @@ +# Gradle plugin + +This plugin adds completions and aliases for [Gradle](https://gradle.org/). + +To use it, add `gradle` to the plugins array in your bashrc file: + +```bash +plugins=(... gradle) +``` + +## Usage + +This plugin creates a function called `gradle-or-gradlew`, which is aliased +to `gradle`, which is used to determine whether the current project directory +has a gradlew file. If `gradlew` is present it will be used, otherwise `gradle` +is used instead. Gradle tasks can be executed directly without regard for +whether it is `gradle` or `gradlew`. It also supports being called from +any directory inside the root project directory. + +Examples: + +```bash +gradle test +gradle build +``` diff --git a/plugins/gradle/gradle.plugin.sh b/plugins/gradle/gradle.plugin.sh new file mode 100644 index 000000000..03d00b4d2 --- /dev/null +++ b/plugins/gradle/gradle.plugin.sh @@ -0,0 +1,24 @@ +#! bash oh-my-bash.module + +function gradle-or-gradlew() { + # find project root + # taken from https://github.com/gradle/gradle-completion + local dir="$PWD" project_root="$PWD" + while [[ "$dir" != / ]]; do + if [[ -x "$dir/gradlew" ]]; then + project_root="$dir" + break + fi + dir="${dir:h}" + done + + # if gradlew found, run it instead of gradle + if [[ -f "$project_root/gradlew" ]]; then + echo "executing gradlew instead of gradle" + "$project_root/gradlew" "$@" + else + command gradle "$@" + fi +} + +alias gradle=gradle-or-gradlew