You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by gn...@apache.org on 2026/03/21 12:48:19 UTC
(camel) 01/01: CAMEL-23226: Enhance Shell with alias persistence and init script support
This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch CAMEL-23226-shell-enhancements
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 586f5dff8e73d10e753c8d77533bfb366d5b1026
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Sat Mar 21 13:48:02 2026 +0100
CAMEL-23226: Enhance Shell with alias persistence and init script support
- Add DefaultAliasManager with persistence at ~/.camel-jbang-aliases
for persistent alias/unalias commands
- Add init script support via ~/.camel-jbang-init file
- Remove scriptCommands(true) which requires a scriptRunner to function
Co-Authored-By: Claude Opus 4.6 <no...@anthropic.com>
---
.../camel/dsl/jbang/core/commands/Shell.java | 27 ++++++++++++++++++----
1 file changed, 22 insertions(+), 5 deletions(-)
diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Shell.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Shell.java
index 433ba21d9c5a..c550f328fbce 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Shell.java
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Shell.java
@@ -16,6 +16,7 @@
*/
package org.apache.camel.dsl.jbang.core.commands;
+import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -24,6 +25,7 @@ import org.jline.builtins.InteractiveCommandGroup;
import org.jline.builtins.PosixCommandGroup;
import org.jline.picocli.PicocliCommandRegistry;
import org.jline.reader.LineReader;
+import org.jline.shell.impl.DefaultAliasManager;
import picocli.CommandLine;
@CommandLine.Command(name = "shell",
@@ -39,20 +41,35 @@ public class Shell extends CamelCommand {
public Integer doCall() throws Exception {
PicocliCommandRegistry registry = new PicocliCommandRegistry(CamelJBangMain.getCommandLine());
- Path history = Paths.get(HomeHelper.resolveHomeDir(), ".camel-jbang-history");
+ String homeDir = HomeHelper.resolveHomeDir();
+ Path history = Paths.get(homeDir, ".camel-jbang-history");
- try (org.jline.shell.Shell shell = org.jline.shell.Shell.builder()
+ // Alias persistence: aliases are stored in ~/.camel-jbang-aliases
+ Path aliasFile = Paths.get(homeDir, ".camel-jbang-aliases");
+ DefaultAliasManager aliasManager = new DefaultAliasManager(aliasFile);
+
+ // Init script: if ~/.camel-jbang-init exists, it will be executed on shell startup
+ Path initScript = Paths.get(homeDir, ".camel-jbang-init");
+
+ org.jline.shell.ShellBuilder builder = org.jline.shell.Shell.builder()
.prompt("camel> ")
.groups(registry, new PosixCommandGroup(), new InteractiveCommandGroup())
.historyFile(history)
.historyCommands(true)
.helpCommands(true)
- .scriptCommands(true)
.variableCommands(true)
.commandHighlighter(true)
+ .aliasManager(aliasManager)
+ // scriptCommands(true) requires a scriptRunner to be set;
+ // omitting for now until a DefaultScriptRunner is available
.variable(LineReader.LIST_MAX, 50)
- .option(LineReader.Option.GROUP_PERSIST, true)
- .build()) {
+ .option(LineReader.Option.GROUP_PERSIST, true);
+
+ if (Files.exists(initScript)) {
+ builder.initScript(initScript.toFile());
+ }
+
+ try (org.jline.shell.Shell shell = builder.build()) {
shell.run();
}
return 0;