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


The following commit(s) were added to refs/heads/master by this push:
     new bb295608ea GROOVY-8162: Update Groovysh to JLine3 (completion for /cd 
and fix workDir references)
bb295608ea is described below

commit bb295608ea1b00e80f6dd5aa1576bb6e30c00bf1
Author: Paul King <pa...@asert.com.au>
AuthorDate: Tue Aug 12 09:33:00 2025 +1000

    GROOVY-8162: Update Groovysh to JLine3 (completion for /cd and fix workDir 
references)
---
 .../src/main/groovy/org/apache/groovy/groovysh/Main.groovy        | 8 ++++++--
 .../groovy/org/apache/groovy/groovysh/jline/GroovyCommands.groovy | 6 +++---
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git 
a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Main.groovy
 
b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Main.groovy
index 66ee577d0d..74c6e0b0c8 100644
--- 
a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Main.groovy
+++ 
b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Main.groovy
@@ -107,7 +107,7 @@ class Main {
             def cmds = [
                 '/clear': new CommandMethods((Function) this::clear, 
this::defaultCompleter),
                 '/pwd'  : new CommandMethods((Function) this::pwd, 
this::defaultCompleter),
-                '/cd'   : new CommandMethods((Function) this::cd, 
this::defaultCompleter),
+                '/cd'   : new CommandMethods((Function) this::cd, 
this::optDirCompleter),
                 '/date' : new CommandMethods((Function) this::date, 
this::defaultCompleter),
                 '/echo' : new CommandMethods((Function) this::echo, 
this::defaultCompleter),
                 "/!"    : new CommandMethods((Function) this::shell, 
this::defaultCompleter)
@@ -150,6 +150,10 @@ class Main {
             [new ArgumentCompleter(NullCompleter.INSTANCE, new 
Completers.OptionCompleter(new Completers.FilesCompleter(this::currentDir), 
this::commandOptions, 1))]
         }
 
+        private List<Completer> optDirCompleter(String command) {
+            [new ArgumentCompleter(NullCompleter.INSTANCE, new 
Completers.OptionCompleter(new 
Completers.DirectoriesCompleter(this::currentDir), this::commandOptions, 1))]
+        }
+
         private void pwd(CommandInput input) {
             posix(adjustUsage('pwd', '/pwd'), input)
         }
@@ -371,7 +375,7 @@ class Main {
                 if (!OSUtils.IS_WINDOWS) {
                     setSpecificHighlighter("/!", 
SyntaxHighlighter.build(jnanorc, "SH-REPL"))
                 }
-                addFileHighlight('/nano', '/less', '/slurp', '/load', '/save', 
*POSIX_FILE_CMDS)
+                addFileHighlight('/nano', '/less', '/slurp', '/load', '/save', 
*POSIX_FILE_CMDS, '/cd')
                 addFileHighlight('/classloader', null, ['-a', '--add'])
                 addExternalHighlighterRefresh(printer::refresh)
                 addExternalHighlighterRefresh(scriptEngine::refresh)
diff --git 
a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyCommands.groovy
 
b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyCommands.groovy
index afcb0acd72..ab12f86a5e 100644
--- 
a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyCommands.groovy
+++ 
b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyCommands.groovy
@@ -198,7 +198,7 @@ class GroovyCommands extends JlineCommandRegistry 
implements CommandRegistry {
             overwrite = true
             arg = input.args()[1]
         }
-        saveFile(engine, new File(arg), overwrite)
+        saveFile(engine, workDir.get().resolve(arg).toFile(), overwrite)
     }
 
     static void saveFile(GroovyEngine engine, File file, boolean overwrite = 
false) {
@@ -228,7 +228,7 @@ class GroovyCommands extends JlineCommandRegistry 
implements CommandRegistry {
             merge = true
             arg = input.args()[1]
         }
-        loadFile(engine, new File(arg), merge)
+        loadFile(engine, workDir.get().resolve(arg).toFile(), merge)
     }
 
     void slurpcmd(CommandInput input) {
@@ -264,7 +264,7 @@ class GroovyCommands extends JlineCommandRegistry 
implements CommandRegistry {
             throw new IllegalArgumentException("Invalid parameter type: " + 
arg.getClass().simpleName)
         }
         try {
-            Path path = Paths.get(arg)
+            Path path = workDir.get().resolve(arg)
             if (Files.exists(path)) {
                 if (!format) {
                     def ext = path.extension

Reply via email to