Automatically generate tab completions for CLI tools by analyzing their --help output and man pages.
TabGen scans your system for executable tools that you actually use (based on shell history), parses their help documentation, and generates working tab completion scripts for both Bash and Zsh. It works alongside existing completions without overwriting them, using intelligent caching to avoid unnecessary regeneration.
go install github.com/jvalentini/tabgen@latest# 1. Install TabGen
go install github.com/jvalentini/tabgen@latest
# 2. Scan your PATH for executables (filters by shell history)
tabgen scan
# 3. Generate completions for a specific tool
tabgen generate kubectl
# 4. Or generate for all discovered tools (uses concurrent workers)
tabgen generate
# 5. Optional: Force regeneration with verbose output
tabgen -v generate --force
# 6. Install shell hooks and symlinks
tabgen install
# 7. Restart your shell or source your rc file
source ~/.bashrc # for bash
source ~/.zshrc # for zsh
# 8. Start using completions!
kubectl get <TAB> # Shows: pods, services, deployments, etc.
kubectl get pods --<TAB> # Shows: --all-namespaces, --field-selector, etc.| Command | Description |
|---|---|
tabgen scan |
Discover executables in $PATH that appear in shell history |
tabgen generate [tool] |
Generate completions for one or all tools (concurrent by default) |
tabgen generate -f|--force |
Force regeneration even if up-to-date |
tabgen generate -w|--workers N |
Set number of concurrent workers (default: CPU count) |
tabgen list |
Show discovered tools with generation status |
tabgen list --all |
Show all tools including those without completions |
tabgen install |
Set up symlinks, shell hooks, and daily scan timer |
tabgen install --skip-timer |
Install without setting up automatic scanning |
tabgen uninstall |
Remove all TabGen artifacts |
tabgen uninstall --keep-data |
Uninstall but keep generated completions |
tabgen status |
Show installation health and statistics |
tabgen exclude list |
Show excluded tool patterns |
tabgen exclude add <pattern> |
Add a tool or pattern to exclusions |
tabgen exclude remove <pattern> |
Remove a pattern from exclusions |
tabgen exclude clear |
Clear all exclusions |
Global Options:
-v, --verbose: Show detailed parsing and debug output
-
Scan: TabGen walks your
$PATHdirectories and discovers executable files that appear in your shell history (.bash_history,.zsh_history). This focuses on tools you actually use, avoiding clutter from rarely-used binaries. Metadata is stored in a catalog. -
Parse: For each tool, TabGen runs
--help(or-h) and reads man pages to extract:- Subcommands and their descriptions
- Flags (short and long forms)
- Flag arguments and allowed values
- Nested subcommands (up to 2 levels deep)
- Command aliases
-
Generate: The parsed data is transformed into shell-specific completion scripts using concurrent processing:
- Bash: Uses
completebuiltins with fallback behavior - Zsh: Generates
_toolcompletion functions with_arguments - Supports parallel generation with configurable workers
- Bash: Uses
-
Install: Symlinks are created to standard completion directories, and shell hooks are added to your rc files. Optionally sets up daily automatic scanning via systemd timers or cron.
TabGen stores all data in ~/.tabgen/:
~/.tabgen/
├── config.json # Settings (exclusions, scan options)
├── catalog.json # Discovered tools and metadata
├── tools/
│ └── <tool>.json # Parsed structure per tool
└── completions/
├── bash/
│ └── <tool> # Generated bash completions
└── zsh/
└── _<tool> # Generated zsh completions
Each tools/<tool>.json file contains structured data:
{
"name": "kubectl",
"version": "1.28.0",
"parsed_at": "2024-01-15T10:30:00Z",
"source": "help",
"subcommands": [
{
"name": "get",
"aliases": ["g"],
"description": "Display one or many resources",
"flags": [
{
"name": "--output",
"short": "-o",
"arg": "format",
"argument_values": ["json", "yaml", "wide"],
"description": "Output format"
}
],
"subcommands": []
}
],
"global_flags": [
{
"name": "--help",
"short": "-h",
"description": "Show help"
}
]
}catalog.json tracks all discovered tools:
{
"last_scan": "2024-01-15T10:00:00Z",
"tools": {
"kubectl": {
"name": "kubectl",
"path": "/usr/local/bin/kubectl",
"version": "1.28.0",
"generated_version": "1.28.0",
"content_hash": "a1b2c3d4...",
"generated": true,
"last_scan": "2024-01-15T10:00:00Z",
"has_help": true,
"has_man_page": true
}
}
}Only generates completions for tools you actually use. TabGen scans .bash_history and .zsh_history to identify frequently-used commands, avoiding wasted effort on rarely-used binaries in your $PATH.
TabGen uses two mechanisms to avoid unnecessary regeneration:
- Version detection: Tracks tool versions and only regenerates when updated
- Content hashing: Detects changes in help output even when version numbers don't change
Use --force to regenerate regardless of these checks.
Generation uses parallel workers (default: CPU count) for fast processing of large catalogs:
tabgen generate -w 8 # Use 8 workersParses multi-level command structures like docker container ls or kubectl get pods up to 2 levels deep.
Skip tools that don't need completions or cause issues:
tabgen exclude add python2.7
tabgen exclude add "*.dll"The install command sets up either:
- Systemd timer (Linux with systemd): Daily scan via user timer
- Cron job: Daily scan at 4am as fallback
TabGen completions work alongside existing system completions:
- Bash: Uses
complete -o default -o bashdefaultto supplement - Zsh: Places TabGen's fpath after system paths
The ~/.tabgen/config.json file contains:
{
"tabgen_dir": "~/.tabgen",
"excluded": ["python2.7", "*.dll"],
"scan_on_startup": true
}- PATH Discovery: Walks all directories in
$PATHenvironment variable - History Parsing: Reads
.bash_historyand.zsh_historyto identify used commands - Filtering: Applies exclusion patterns and filters for executables in history
- Cataloging: Stores metadata (path, version, timestamps) in
catalog.json
- Help Execution: Runs
<tool> --helpwith 5-second timeout - Man Page Fallback: Reads
man <tool>if help fails or as supplement - Regex Extraction: Parses output for:
- Section headers (Commands:, Options:, Flags:)
- Flag patterns:
-f, --flag <arg>,--flag=value, etc. - Subcommand patterns with descriptions
- Argument value lists:
{json,yaml},json|yaml
- Structure Building: Creates nested Command/Flag hierarchy
- JSON Storage: Saves to
tools/<tool>.json
- Worker Pool: Creates N workers (default: CPU count)
- Version Check: Compares current version/hash with generated version/hash
- Skip Logic: Skips if unchanged (unless
--force) - Bash Generation: Creates completion function using
_init_completionandcompgen - Zsh Generation: Creates completion function using
_argumentsand_describe - Catalog Update: Marks tool as generated with current version/hash
Bash:
- Symlinks created in
~/.local/share/bash-completion/completions/ - Shell hook in
~/.bashrcadds TabGen completion directory to path complete -o default -o bashdefaultallows fallback to system completions
Zsh:
- Symlinks created in
~/.zfunc/ - Shell hook in
~/.zshrcadds~/.zfuncto$fpath - Zsh's completion system loads functions automatically
- TabGen's
fpathentry placed after system paths for proper precedence
- Bash: Full completion support with
_init_completionandcompgen - Zsh: Full completion support with
_argumentsand_describe
TabGen extracts the following from --help output and man pages:
- Primary names:
clone,push,pull - Aliases:
brforbranch,coforcheckout - Descriptions: One-line help text
- Nested subcommands: Up to 2 levels (e.g.,
docker container ls)
- Long form:
--output,--verbose - Short form:
-o,-v - Arguments:
<file>,<format>,VALUE - Allowed values:
json|yaml,{json,yaml,wide} - Descriptions: Help text for each flag
Command sections:
Commands:Available Commands:Subcommands:
Flag sections:
Options:Flags:Global Options:Global Flags:
Flag formats:
-f, --flag(short and long)--flag=VALUE(with argument)--flag <value>(with argument)--format {json,yaml}(with choices)--format json|yaml(with choices)
TabGen is designed for speed and efficiency:
- Concurrent generation: Uses all CPU cores by default (configurable with
-w) - Smart caching: Only regenerates when tool versions or help output change
- Quick scanning: Default scan mode skips slow
--helpchecks - History filtering: Only processes tools you actually use
Example performance on a typical system:
- Scan 500 tools from PATH: ~1 second
- Generate 50 completions: ~5 seconds (8-core CPU)
- Incremental regeneration: ~1 second (only changed tools)
tabgen statusSome tools have non-standard help formats. TabGen works best with tools that follow common conventions:
- GNU-style flags (
--option,-o) - Section headers like "Commands:", "Options:", "Flags:"
- Man pages with OPTIONS sections
If a tool isn't generating properly:
- Check verbose output:
tabgen -v generate <tool> - Verify the tool appears in shell history (required for scan)
- Add problematic tools to exclusions if they cause issues
- Ensure shell hooks are installed:
tabgen status - Restart your shell or source your rc file
- Check that completion directories exist and are readable
- Verify symlinks are valid:
ls -la ~/.local/share/bash-completion/completions/
If generation is slow:
- Increase workers:
tabgen generate -w 16 - Generate specific tools only:
tabgen generate kubectl docker - Add exclusions for problematic tools that hang on
--help
MIT
