zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] Fix gradlew completion
@ 2023-09-22  2:50 Shohei YOSHIDA
  2023-09-22 23:36 ` Oliver Kiddle
  0 siblings, 1 reply; 3+ messages in thread
From: Shohei YOSHIDA @ 2023-09-22  2:50 UTC (permalink / raw)
  To: zsh-workers; +Cc: Shohei YOSHIDA

gradlew is not usually in the PATH so the command to retrieve tasks would fail
due to 'command not found'. So it should execute './gradlew' instead of 'gradle'
if service is gradlew and there is an executable file './gradlew' in current
directory
---
 Completion/Unix/Command/_gradle | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/Completion/Unix/Command/_gradle b/Completion/Unix/Command/_gradle
index c1f7c05ee..734429288 100644
--- a/Completion/Unix/Command/_gradle
+++ b/Completion/Unix/Command/_gradle
@@ -91,8 +91,13 @@ if [[ $state == task && ! -prefix - ]]; then
             if _cache_invalid $cache_name || ! _retrieve_cache $cache_name; then
                 zle -R "Generating cache from $gradle_buildfile"
 
+                local gradle_command=$service
+                if [[ $service == gradlew && -x ./gradlew ]]; then
+                    gradle_command='./gradlew'
+                fi
+
                 # Run gradle/gradlew and retrieve possible tasks.
-                for outputline in ${(f)"$($service --build-file $gradle_buildfile -q tasks --all)"}; do
+                for outputline in ${(f)"$($gradle_command --build-file $gradle_buildfile -q tasks --all)"}; do
 
                     # Tasks and subprojects each start with a lowercase letter, but whereas tasks are in camelCase, each
                     # subproject consists of one or more sections of kebab-case, with each section ending in a ':'.
-- 
2.39.2



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fix gradlew completion
  2023-09-22  2:50 [PATCH] Fix gradlew completion Shohei YOSHIDA
@ 2023-09-22 23:36 ` Oliver Kiddle
  2023-09-23  3:13   ` Shohei Yoshida
  0 siblings, 1 reply; 3+ messages in thread
From: Oliver Kiddle @ 2023-09-22 23:36 UTC (permalink / raw)
  To: Shohei YOSHIDA; +Cc: zsh-workers

Shohei YOSHIDA wrote:
> gradlew is not usually in the PATH so the command to retrieve tasks would fail
> due to 'command not found'. So it should execute './gradlew' instead of 'gradle'
> if service is gradlew and there is an executable file './gradlew' in current
> directory

Trying to run $service from a completion function is nearly always
wrong because any path prefix has first been stripped. Rather than
trying to handle the current directory, it is probably better to just
use $words[1] instead. Then if someone completes after ../gradlew or
/somewhere/else/gradlew then it will use the location they specified.
If there is no gradlew there, they're going to have other problems when
they try to execute it anyway.

Oliver


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fix gradlew completion
  2023-09-22 23:36 ` Oliver Kiddle
@ 2023-09-23  3:13   ` Shohei Yoshida
  0 siblings, 0 replies; 3+ messages in thread
From: Shohei Yoshida @ 2023-09-23  3:13 UTC (permalink / raw)
  To: Oliver Kiddle; +Cc: zsh-workers


[-- Attachment #1.1: Type: text/plain, Size: 1200 bytes --]

On Sat, Sep 23, 2023 at 8:36 AM Oliver Kiddle <opk@zsh.org> wrote:

> Shohei YOSHIDA wrote:
> > gradlew is not usually in the PATH so the command to retrieve tasks
> would fail
> > due to 'command not found'. So it should execute './gradlew' instead of
> 'gradle'
> > if service is gradlew and there is an executable file './gradlew' in
> current
> > directory
>
> Trying to run $service from a completion function is nearly always
> wrong because any path prefix has first been stripped. Rather than
> trying to handle the current directory, it is probably better to just
> use $words[1] instead. Then if someone completes after ../gradlew or
> /somewhere/else/gradlew then it will use the location they specified.
> If there is no gradlew there, they're going to have other problems when
> they try to execute it anyway.
>
> Oliver
>

Thanks for reviewing.
I have updated the patch and attached it.

-- 
Shohei YOSHIDA(syohex@gmail.com)
<http://b.hatena.ne.jp/entry/https://mail.google.com/_/scs/mail-static/_/js/k=gmail.main.ja.tLQrNXCHmdo.O/m=m_i,t,it/am=nBHH5b_7g8gZ7tIn1f7977tLmp39J3_3JgBC2Amo_5v9P4jWA_ug_FA/rt=h/d=1/t=zcms/rs=AItRSTNJwrjV1i8LKqdsHFfbx47Tnlb-Bw>

[-- Attachment #1.2: Type: text/html, Size: 2115 bytes --]

[-- Attachment #2: 0001-Fix-gradlew-completion.patch --]
[-- Type: text/x-patch, Size: 1322 bytes --]

From 9ef5a75239316033c3db0d3dee60fea31b91b420 Mon Sep 17 00:00:00 2001
From: Shohei YOSHIDA <syohex@gmail.com>
Date: Fri, 22 Sep 2023 11:36:21 +0900
Subject: [PATCH] Fix gradlew completion

gradlew is not usually in the PATH so the command to retrieve tasks would fail
due to 'command not found'. The location is stripped from '$service' so use
'$words[1]' instead of '$service'
---
 Completion/Unix/Command/_gradle | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Completion/Unix/Command/_gradle b/Completion/Unix/Command/_gradle
index c1f7c05ee..280aa243f 100644
--- a/Completion/Unix/Command/_gradle
+++ b/Completion/Unix/Command/_gradle
@@ -92,7 +92,7 @@ if [[ $state == task && ! -prefix - ]]; then
                 zle -R "Generating cache from $gradle_buildfile"
 
                 # Run gradle/gradlew and retrieve possible tasks.
-                for outputline in ${(f)"$($service --build-file $gradle_buildfile -q tasks --all)"}; do
+                for outputline in ${(f)"$($words[1] --build-file $gradle_buildfile -q tasks --all)"}; do
 
                     # Tasks and subprojects each start with a lowercase letter, but whereas tasks are in camelCase, each
                     # subproject consists of one or more sections of kebab-case, with each section ending in a ':'.
-- 
2.39.2


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-09-23  3:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-22  2:50 [PATCH] Fix gradlew completion Shohei YOSHIDA
2023-09-22 23:36 ` Oliver Kiddle
2023-09-23  3:13   ` Shohei Yoshida

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).