Add shell completion generation (bash, zsh, fish)#127
Merged
Conversation
Plan and process docs for incremental TDD development of shell completion generation (issue #45). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Opt-in via `require "clamp/completion"`, then:
MyCommand.generate_completion(:fish, "myapp")
Walks the command tree to generate `complete -c` registrations using
fish builtins __fish_use_subcommand and __fish_seen_subcommand_from.
Handles inherited options, aliases, hidden option exclusion, and
subcommand classes reused across the tree.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Demonstrates shell completion generation with subcommands, inherited options, and --[no-]commit expansion. gitdown --completion fish gitdown --completion bash Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Provides a ready-made subcommand for generating shell completions:
subcommand "completion", "Generate shell completions",
Clamp::Completion::Command
Then users run: myapp completion fish
The root command class and executable name are inferred at runtime
from context and invocation_path.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The SHELL parameter now accepts full paths (e.g. /usr/bin/fish) and defaults to the $SHELL environment variable. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When clamp/completion is loaded, every command gets a hidden
--shell-completions SHELL option. Like --help, it raises an
exception caught by .run, printing the completion script to stdout.
Works on commands without subcommands:
myapp --shell-completions fish
myapp --shell-completions /usr/bin/fish
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The implicit --shell-completions option makes the explicit subcommand class unnecessary. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Generate bash completion scripts with subcommand-aware completions, option/flag handling, and valued-option detection. Extracts shared tree-walking utilities (walk_command_tree, collect_subcommand_names) into the Completion module for reuse across generators. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Generate zsh completion scripts using _arguments with state-machine dispatch for subcommands. Per-node functions use -C flag with ->commands/->args states, _describe for subcommand listings, brace expansion for short/long switch aliases, and mutual exclusion specs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Redesign walk_command_tree so all generators can use it: - Path is now an array of Subcommand::Definition objects - Always yields (even for revisited classes), with has_children flag - Yields 3 args: (command_class, path, has_children) Rewrite FishGenerator to use the shared walker instead of its own recursive generate_command/generate_subcommands methods. Update BashGenerator for the new API. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
cfa69d4 to
be2f2d6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds shell completion script generation for bash, zsh, and fish. Closes #45.
require "clamp/completion", which adds a hidden--shell-completions SHELLoption to all commandsMyCommand.generate_completion(:bash, "myapp")--[no-]variants), subcommand names/aliases, and--helpNew files
lib/clamp/completion.rb— entry point, shared utilities, implicit optionlib/clamp/completion/bash_generator.rb— bash completion generatorlib/clamp/completion/zsh_generator.rb— zsh completion generatorlib/clamp/completion/fish_generator.rb— fish completion generatorspec/clamp/completion_spec.rb— 54 specs including syntax validationTest plan
bundle exec rspec— 271 examples, 0 failuresbundle exec rubocop— 0 offensesbash -n,zsh -n,fish --no-execute)🤖 Generated with Claude Code