This is an automated email from the ASF dual-hosted git repository. gnodet pushed a commit to branch CAMEL-23226-all-jbang-ux in repository https://gitbox.apache.org/repos/asf/camel.git
commit 2de3b67391c865c4bcca6734274a52406384c420 Author: Guillaume Nodet <[email protected]> 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 <[email protected]> --- .../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;
