Project 13: Tab Completion Engine
A context-aware completion system that completes commands, filenames, options, and custom completions (like git branch names), with support for multiple matches and disambiguation.
Quick Reference
| Attribute | Value |
|---|---|
| Primary Language | C |
| Alternative Languages | Rust, Go, Python |
| Difficulty | Level 3: Advanced (The Engineer) |
| Time Estimate | 1-2 weeks |
| Knowledge Area | UI/UX / Filesystem |
| Tooling | Shell Completion |
| Prerequisites | Projects 10-12, understanding of $PATH |
What You Will Build
A context-aware completion system that completes commands, filenames, options, and custom completions (like git branch names), with support for multiple matches and disambiguation.
Why It Matters
This project builds core skills that appear repeatedly in real-world systems and tooling.
Core Challenges
- Context detection (first word = command, later = argument) → maps to parsing context
- Command completion (search $PATH for executables) → maps to path handling
- Filename completion (directory traversal with prefix matching) → maps to filesystem
- Multiple matches (show options, find common prefix) → maps to UI design
- Programmable completion (command-specific completers) → maps to extensibility
Key Concepts
- Programmable completion: “Bash Reference Manual” Section 8.6 - GNU
- readline completion API: “GNU Readline Library” Section 2.6 - GNU
- Completion frameworks: bash-completion project (GitHub/scop)
Real-World Outcome
$ ./mysh
mysh> gi<TAB>
git gist gimp
mysh> git<TAB>
mysh> git <TAB>
add branch checkout commit diff ...
mysh> git check<TAB>
mysh> git checkout <TAB>
main feature-x bugfix-123
mysh> ls /usr/lo<TAB>
mysh> ls /usr/local/<TAB>
bin/ include/ lib/ share/
mysh> cd ~/Doc<TAB>
mysh> cd ~/Documents/
Implementation Guide
- Reproduce the simplest happy-path scenario.
- Build the smallest working version of the core feature.
- Add input validation and error handling.
- Add instrumentation/logging to confirm behavior.
- Refactor into clean modules with tests.
Milestones
- Milestone 1: Minimal working program that runs end-to-end.
- Milestone 2: Correct outputs for typical inputs.
- Milestone 3: Robust handling of edge cases.
- Milestone 4: Clean structure and documented usage.
Validation Checklist
- Output matches the real-world outcome example
- Handles invalid inputs safely
- Provides clear errors and exit codes
- Repeatable results across runs
References
- Main guide:
SHELL_INTERNALS_DEEP_DIVE_PROJECTS.md - “Bash Reference Manual” by GNU