Skip to content

Commit

Permalink
feat: added Gradle plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
chriptus13 committed Oct 4, 2024
1 parent e712342 commit b430b69
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
25 changes: 25 additions & 0 deletions plugins/gradle/README.md
Original file line number Diff line number Diff line change
@@ -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
```
24 changes: 24 additions & 0 deletions plugins/gradle/gradle.plugin.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b430b69

Please sign in to comment.