You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2025/08/23 09:04:48 UTC

(groovy) branch master updated (c3c6825518 -> ca66fb66f1)

This is an automated email from the ASF dual-hosted git repository.

paulk pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


    from c3c6825518 fix relative link for groovysh
     new a0297f77cc GROOVY-11740: hook up glob support for groovysh /grep
     new ca66fb66f1 GROOVY-11741: provide header control switches for groovysh /grep inspired by ubuntu grep

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../groovy/groovysh/jline/GroovyPosixCommands.java | 37 ++++++++++++++++++----
 1 file changed, 31 insertions(+), 6 deletions(-)


(groovy) 01/02: GROOVY-11740: hook up glob support for groovysh /grep

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit a0297f77ccc53540100a5fc244afb7392065176c
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sat Aug 23 19:02:50 2025 +1000

    GROOVY-11740: hook up glob support for groovysh /grep
---
 .../groovy/org/apache/groovy/groovysh/jline/GroovyPosixCommands.java | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyPosixCommands.java b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyPosixCommands.java
index e20a9aeae9..c06803a1e7 100644
--- a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyPosixCommands.java
+++ b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyPosixCommands.java
@@ -581,8 +581,9 @@ public class GroovyPosixCommands extends PosixCommands {
             if ("-".equals(arg)) {
                 sources.add(new GrepSource(context.in(), "(standard input)"));
             } else {
-                Path path = context.currentDir().resolve(arg);
-                sources.add(new GrepSource(path, arg));
+                sources.addAll(maybeExpandGlob(context, arg).stream()
+                    .map(gp -> new GrepSource(gp, gp.toString()))
+                    .collect(Collectors.toList()));
             }
         }
         boolean match = false;


(groovy) 02/02: GROOVY-11741: provide header control switches for groovysh /grep inspired by ubuntu grep

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit ca66fb66f1281c3d4826f14b1b16228dcf057cf7
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sat Aug 23 19:04:36 2025 +1000

    GROOVY-11741: provide header control switches for groovysh /grep inspired by ubuntu grep
---
 .../groovy/groovysh/jline/GroovyPosixCommands.java | 32 +++++++++++++++++++---
 1 file changed, 28 insertions(+), 4 deletions(-)

diff --git a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyPosixCommands.java b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyPosixCommands.java
index c06803a1e7..4019daabd5 100644
--- a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyPosixCommands.java
+++ b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyPosixCommands.java
@@ -501,6 +501,9 @@ public class GroovyPosixCommands extends PosixCommands {
             "  -w --word-regexp         Select only whole words",
             "  -x --line-regexp         Select only whole lines",
             "  -c --count               Only print a count of matching lines per file",
+            "  -z --zero                When used with -c, don't print a count of zero",
+            "  -h --header              Display filename header for each file (defaults to true if multiple files are given)",
+            "  -H --no-filename         Do not display filename header",
             "     --color=WHEN          Use markers to distinguish the matching string, may be `always', `never' or `auto'",
             "  -B --before-context=NUM  Print NUM lines of leading context before matching lines",
             "  -A --after-context=NUM   Print NUM lines of trailing context after matching lines",
@@ -546,6 +549,7 @@ public class GroovyPosixCommands extends PosixCommands {
             before = contextLines;
         }
         boolean count = opt.isSet("count");
+        boolean zero = opt.isSet("zero");
         boolean quiet = opt.isSet("quiet");
         boolean invert = opt.isSet("invert-match");
         boolean lineNumber = opt.isSet("line-number");
@@ -586,6 +590,12 @@ public class GroovyPosixCommands extends PosixCommands {
                     .collect(Collectors.toList()));
             }
         }
+        boolean filenameHeader = sources.size() > 1;
+        if (opt.isSet("header")) {
+            filenameHeader = true;
+        } else if (opt.isSet("no-filename")) {
+            filenameHeader = false;
+        }
         boolean match = false;
         for (GrepSource src : sources) {
             List<String> lines = new ArrayList<>();
@@ -605,7 +615,7 @@ public class GroovyPosixCommands extends PosixCommands {
                         if (matches) {
                             nb++;
                             if (!count && !quiet) {
-                                if (sources.size() > 1) {
+                                if (filenameHeader) {
                                     if (colored) {
                                         applyStyle(sbl, colors, "fn");
                                     }
@@ -649,7 +659,7 @@ public class GroovyPosixCommands extends PosixCommands {
                         } else if (lineMatch > 0) {
                             context.out().println(lines.remove(0));
                             lineMatch--;
-                            if (sources.size() > 1) {
+                            if (filenameHeader) {
                                 if (colored) {
                                     applyStyle(sbl, colors, "fn");
                                 }
@@ -674,7 +684,7 @@ public class GroovyPosixCommands extends PosixCommands {
                             }
                             sbl.append(line);
                         } else {
-                            if (sources.size() > 1) {
+                            if (filenameHeader) {
                                 if (colored) {
                                     applyStyle(sbl, colors, "fn");
                                 }
@@ -725,7 +735,21 @@ public class GroovyPosixCommands extends PosixCommands {
                         }
                     }
                     if (count) {
-                        context.out().println(nb);
+                        if (nb != 0 || !zero) {
+                            AttributedStringBuilder sbl = new AttributedStringBuilder();
+                            if (filenameHeader) {
+                                if (colored) {
+                                    applyStyle(sbl, colors, "fn");
+                                }
+                                sbl.append(src.getName());
+                                if (colored) {
+                                    applyStyle(sbl, colors, "se");
+                                }
+                                sbl.append(":");
+                            }
+                            sbl.append(Integer.toString(nb));
+                            context.out().println(sbl.toAnsi(context.terminal()));
+                        }
                     }
                     match |= nb > 0;
                 }