Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ dependencies {
implementation 'org.jspecify:jspecify:1.0.0'
implementation 'org.apache.commons:commons-text:1.11.0'
implementation 'org.apache.commons:commons-compress:1.27.1'
implementation 'info.picocli:picocli:4.7.7'
implementation 'info.picocli:picocli:4.7.8-SNAPSHOT'
implementation 'io.quarkus.qute:qute-core:1.13.7.Final'
implementation 'kr.motd.maven:os-maven-plugin:1.7.1'
implementation 'org.codehaus.plexus:plexus-java:1.2.0'
Expand Down
27 changes: 24 additions & 3 deletions src/main/java/dev/jbang/cli/Completion.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,31 @@ public Integer doCall() throws IOException {
return completion();
}

@CommandLine.Option(names = { "-s",
"--shell" }, description = {
"Generate bash/zsh or fish completion script for ${ROOT-COMMAND-NAME:-the root command of this command}.",
"Run the following command to give `${ROOT-COMMAND-NAME:-$PARENTCOMMAND}` TAB completion in the current shell:",
"",
" bash/zsh: source <(${PARENT-COMMAND-FULL-NAME:-$PARENTCOMMAND} ${COMMAND-NAME})",
"",
" fish: eval (<(${PARENT-COMMAND-FULL-NAME:-$PARENTCOMMAND} ${COMMAND-NAME} --shell fish)" })
private String shell = "bash";

public int completion() throws IOException {
String script = AutoComplete.bash(
spec.parent().name(),
spec.parent().commandLine());

String script;
if (shell.equals("bash")) {
script = AutoComplete.bash(
spec.parent().name(),
spec.parent().commandLine());
} else if (shell.equals("fish")) {
script = AutoComplete.fish(
spec.parent().name(),
spec.parent().commandLine());
} else {
throw new IllegalArgumentException("Unsupported shell: " + shell);
}

// not PrintWriter.println: scripts with Windows line separators fail in strange
// ways!

Expand Down
Loading