Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added Gradle plugin #625

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down
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/).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This plugin doesn't seem to provide completions. Is there a plan to add them?


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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That code seems to be licensed under the MIT license, meaning that the original copyright notice should be retained. Please include it.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if [[ -f "$project_root/gradlew" ]]; then
if [[ -x "$project_root/gradlew" ]]; then

echo "executing gradlew instead of gradle"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case the user pipes the commands, I think this type of informative message should go to stderr. What do you think?

Suggested change
echo "executing gradlew instead of gradle"
echo "executing gradlew instead of gradle" >&2

"$project_root/gradlew" "$@"
else
command gradle "$@"
fi
}

alias gradle=gradle-or-gradlew