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
Improve aesh's shell completion script generation to support bash, zsh (native), and fish shells with full command model coverage. The existing FileCompleterGenerator provides basic bash support but has significant gaps that prevent real-world CLI tools (like jbang) from generating usable completion scripts.
Current State
FileCompleterGenerator exists and generates basic bash completion scripts. It:
Generates bash functions per command
Handles group commands (subcommands) at one level
Completes option names (long and short)
Includes boolean and default-value completions
Has basic zsh compatibility shims
Gaps
Multi-shell support
No fish completion generation — fish uses complete -c commands with conditions, a completely different format
No native zsh completion — zsh's compdef/_arguments system is far more powerful than the bash compatibility shim currently used
Missing features in bash generation
Nested subcommand hierarchies — deep command trees (e.g., jbang alias add, jbang template list) need proper function nesting
Argument (positional parameter) completion — ProcessedOption with type ARGUMENTS is not handled
Negatable options — --no-{name} forms not generated despite ProcessedOption.isNegatable() support
BashCompletionGenerator — improved version of current FileCompleterGenerator
ZshCompletionGenerator — native zsh compdef/_arguments format
FishCompletionGenerator — fish complete -c format
Fish completion format (reference)
Fish completions use a flat list of complete commands with conditions:
# Subcommands at root levelcomplete-c jbang -f-n"__fish_use_subcommand"-a"run"-d"Builds and runs provided script"complete-c jbang -f-n"__fish_use_subcommand"-a"build"-d"Compiles a script"# Options for a specific subcommandcomplete-c jbang -f-n"__fish_seen_subcommand_from run"-l"java"-s"j"-d"JDK version"complete-c jbang -f-n"__fish_seen_subcommand_from run"-l"debug"-s"d"-d"Launch with debug"# Nested subcommandscomplete-c jbang -f-n"__fish_seen_subcommand_from alias; and not __fish_seen_subcommand_from add list remove"-a"add"-d"Add alias"
Zsh completion format (reference)
#compdef jbang_jbang() {
local -a commands
commands=(
'run:Builds and runs provided script''build:Compiles a script'
)
_arguments -C \
'1:command:->cmd' \
'*::arg:->args'case$statein
cmd) _describe 'command' commands ;;
args) _jbang_${words[1]} ;;
esac
}
Public API for one-shot tools
Add a utility method accessible without interactive mode:
AeshRuntimeRunner.builder()
.command(JBang.class)
.generateCompletion(ShellType.BASH) // outputs script and exits
.execute();
Motivation
jbang migrated from picocli to aesh. picocli provided AutoComplete.bash() for bash/zsh completion. jbang also had a custom fish completion generator (~260 lines). Both were lost in the migration because aesh's FileCompleterGenerator doesn't cover the needed use cases. Shell completion is a critical user-facing feature for CLI tools.
Summary
Improve aesh's shell completion script generation to support bash, zsh (native), and fish shells with full command model coverage. The existing
FileCompleterGeneratorprovides basic bash support but has significant gaps that prevent real-world CLI tools (like jbang) from generating usable completion scripts.Current State
FileCompleterGeneratorexists and generates basic bash completion scripts. It:Gaps
Multi-shell support
complete -ccommands with conditions, a completely different formatcompdef/_argumentssystem is far more powerful than the bash compatibility shim currently usedMissing features in bash generation
jbang alias add,jbang template list) need proper function nestingProcessedOptionwith typeARGUMENTSis not handled--no-{name}forms not generated despiteProcessedOption.isNegatable()supportFileOptionCompletershould trigger file completion in the script rather than static valuesArchitecture
CompleterCommandis the only entry point; there's no easy programmatic API for one-shot CLI tools usingAeshRuntimeRunnerProposed Design
Shell-specific generators
Create a strategy pattern with a common interface:
Implementations:
BashCompletionGenerator— improved version of currentFileCompleterGeneratorZshCompletionGenerator— native zshcompdef/_argumentsformatFishCompletionGenerator— fishcomplete -cformatFish completion format (reference)
Fish completions use a flat list of
completecommands with conditions:Zsh completion format (reference)
Public API for one-shot tools
Add a utility method accessible without interactive mode:
Or integrate with
AeshRuntimeRunner:Motivation
jbang migrated from picocli to aesh. picocli provided
AutoComplete.bash()for bash/zsh completion. jbang also had a custom fish completion generator (~260 lines). Both were lost in the migration because aesh'sFileCompleterGeneratordoesn't cover the needed use cases. Shell completion is a critical user-facing feature for CLI tools.Related