You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Aesh can generate static completion scripts for **bash**, **zsh**, and **fish** shells. These scripts provide tab completion for your CLI tool's command names, option names, option aliases, negated forms, and default values without requiring a running JVM.
161
+
Aesh can generate completion scripts for **bash**, **zsh**, and **fish** shells. There are two approaches:
162
+
163
+
-**Static scripts** — complete option names, subcommand names, and default values without a running JVM. Fast and zero-overhead, but cannot run custom `OptionCompleter` logic.
164
+
-**Dynamic callback scripts** — thin shell shims that call back to your program at tab-time via `--aesh-complete`, running the full aesh completion engine (including custom completers). Ideal for GraalVM native images where startup is near-instant.
| Best for | Option names, default values | Runtime-dependent completions |
162
174
163
175
### Supported Shells
164
176
@@ -168,9 +180,11 @@ Aesh can generate static completion scripts for **bash**, **zsh**, and **fish**
168
180
| Zsh |`ZshCompletionGenerator`| Native `compdef`/`_arguments` format |
169
181
| Fish |`FishCompletionGenerator`|`complete -c` commands with conditions |
170
182
171
-
### Quick Start with AeshRuntimeRunner
183
+
### Static Completion Scripts
184
+
185
+
#### Quick Start with AeshRuntimeRunner
172
186
173
-
The simplest way to add completion generation to your CLI tool:
187
+
The simplest way to add static completion generation to your CLI tool:
174
188
175
189
```java
176
190
publicclassMyApp {
@@ -285,3 +299,93 @@ AeshRuntimeRunner.builder()
285
299
```
286
300
287
301
This writes the completion script to a file named `mycommand.fish` (or `.bash`/`.zsh`).
302
+
303
+
### Dynamic Callback Completion Scripts
304
+
305
+
Dynamic scripts generate thin shell shims that call back to your Java program at tab-time. When the user presses Tab, the shell invokes `myapp --aesh-complete -- <partial-command-line>`, and aesh's full completion engine runs — including all custom `OptionCompleter` implementations.
306
+
307
+
#### Quick Start
308
+
309
+
The simplest approach uses the `handleDynamicCompletion()` helper:
310
+
311
+
```java
312
+
publicclassMyApp {
313
+
publicstaticvoidmain(String[] args) {
314
+
// Handle dynamic completion requests (called by the shell script)
315
+
if (AeshRuntimeRunner.handleDynamicCompletion(args, MyCommand.class)) {
316
+
return;
317
+
}
318
+
319
+
// Check for completion script generation flag
320
+
if (args.length >0&& args[0].equals("--generate-completion")) {
Dynamic callback completion is ideal for GraalVM native images. Since native binaries start in ~10ms, tab completion feels instant. The generated scripts use the program name directly — no special configuration needed:
374
+
375
+
```bash
376
+
# Build native image (e.g., with Maven)
377
+
$ mvn package -Pnative
378
+
379
+
# Generate and install completion — the native binary handles --aesh-complete directly
Copy file name to clipboardExpand all lines: content/docs/aesh/runners.md
+56-2Lines changed: 56 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -470,7 +470,14 @@ public CommandResult execute(CommandInvocation invocation) throws InterruptedExc
470
470
471
471
### Generating Shell Completion Scripts
472
472
473
-
`AeshRuntimeRunner` can generate shell completion scripts (bash, zsh, fish) instead of executing the command. When `generateCompletion()` is set, `execute()` prints the completion script to stdout and returns without running the command.
473
+
`AeshRuntimeRunner` can generate shell completion scripts (bash, zsh, fish) instead of executing the command. There are two modes:
474
+
475
+
-**Static** (`generateCompletion()`) — scripts that complete option names, subcommand names, and default values without a running JVM
476
+
-**Dynamic** (`generateDynamicCompletion()`) — scripts that call back to the program at tab-time via `--aesh-complete`, running custom `OptionCompleter` logic
477
+
478
+
#### Static Completion Scripts
479
+
480
+
When `generateCompletion()` is set, `execute()` prints the static completion script to stdout and returns without running the command.
474
481
475
482
```java
476
483
importorg.aesh.AeshRuntimeRunner;
@@ -514,7 +521,54 @@ AeshRuntimeRunner.builder()
514
521
.execute();
515
522
```
516
523
517
-
See [Completers - Shell Completion Script Generation](../completers#shell-completion-script-generation) for full details on what gets generated and the supported features.
524
+
#### Dynamic Callback Completion
525
+
526
+
Dynamic scripts call back to your program at tab-time, running the full aesh completion engine including custom `OptionCompleter` implementations. This is ideal for GraalVM native images where startup is near-instant (~10ms).
527
+
528
+
Use `handleDynamicCompletion()` to detect and handle the `--aesh-complete` callback, and `generateDynamicCompletion()` to generate the shell script:
$ mytool --completions fish >~/.config/fish/completions/mytool.fish
567
+
```
568
+
569
+
When the user presses Tab, the shell calls `mytool --aesh-complete -- <partial-args>`, the completion engine runs, and candidates are printed one per line to stdout.
570
+
571
+
See [Completers - Shell Completion Script Generation](../completers#shell-completion-script-generation) for full details on static vs dynamic scripts, what gets generated, and GraalVM native image support.
0 commit comments