···11-> A video showcasing how pnpm autocompletions work on a test CLI command
22-> like `my-cli`
11+
3243# tab
5466-Shell autocompletions are largely missing in the JavaScript CLI ecosystem. Tab provides a simple API for adding autocompletions to any JavaScript CLI tool.
55+Shell autocompletions are largely missing in the JavaScript CLI ecosystem. tab provides a simple API for adding autocompletions to any JavaScript CLI tool.
7687Additionally, tab supports autocompletions for `pnpm`, `npm`, `yarn`, and `bun`.
98109As CLI tooling authors, if we can spare our users a second or two by not checking documentation or writing the `-h` flag, we're doing them a huge favor. The unconscious mind loves hitting the [TAB] key and always expects feedback. When nothing happens, it breaks the user's flow - a frustration apparent across the whole JavaScript CLI tooling ecosystem.
11101212-Tab solves this complexity by providing autocompletions that work consistently across `zsh`, `bash`, `fish`, and `powershell`.
1111+tab solves this complexity by providing autocompletions that work consistently across `zsh`, `bash`, `fish`, and `powershell`.
13121413## Installation
1514···92919392## Framework Adapters
94939595-Tab provides adapters for popular JavaScript CLI frameworks.
9494+tab provides adapters for popular JavaScript CLI frameworks.
96959796### CAC Integration
9897···109108 .option('--host <host>', 'Specify host');
110109111110// Initialize tab completions
112112-const completion = tab(cli);
111111+const completion = await tab(cli);
113112114113// Add custom completions for option values
115115-completion.commands.get('dev')?.options.get('--port')!.handler = async () => [
116116- { value: '3000', description: 'Development port' },
117117- { value: '8080', description: 'Production port' },
118118-];
114114+const devCommand = completion.commands.get('dev');
115115+const portOption = devCommand?.options.get('port');
116116+if (portOption) {
117117+ portOption.handler = (complete) => {
118118+ complete('3000', 'Development port');
119119+ complete('8080', 'Production port');
120120+ };
121121+}
119122120123cli.parse();
121124```
···143146const completion = await tab(main);
144147145148// Add custom completions
146146-completion.commands.get('dev')?.options.get('--port')!.handler = async () => [
147147- { value: '3000', description: 'Development port' },
148148- { value: '8080', description: 'Production port' },
149149-];
149149+const devCommand = completion.commands.get('dev');
150150+const portOption = devCommand?.options.get('port');
151151+if (portOption) {
152152+ portOption.handler = (complete) => {
153153+ complete('3000', 'Development port');
154154+ complete('8080', 'Production port');
155155+ };
156156+}
150157151158const cli = createMain(main);
152159cli();
···175182const completion = tab(program);
176183177184// Add custom completions
178178-completion.commands.get('serve')?.options.get('--port')!.handler = async () => [
179179- { value: '3000', description: 'Default port' },
180180- { value: '8080', description: 'Alternative port' },
181181-];
185185+const serveCommand = completion.commands.get('serve');
186186+const portOption = serveCommand?.options.get('port');
187187+if (portOption) {
188188+ portOption.handler = (complete) => {
189189+ complete('3000', 'Default port');
190190+ complete('8080', 'Alternative port');
191191+ };
192192+}
182193183194program.parse();
184195```
185196186186-Tab uses a standardized completion protocol that any CLI can implement:
197197+tab uses a standardized completion protocol that any CLI can implement:
187198188199```bash
189200# Generate shell completion script
···207218208219## Contributing
209220210210-We welcome contributions! Tab's architecture makes it easy to add support for new package managers or CLI frameworks.
221221+We welcome contributions! tab's architecture makes it easy to add support for new package managers or CLI frameworks.
222222+223223+## Acknowledgments
224224+225225+tab was inspired by the great [Cobra](https://github.com/spf13/cobra/) project, which set the standard for CLI tooling in the Go ecosystem.
226226+227227+## Adoption Support
228228+229229+We want to make it as easy as possible for the JS ecosystem to enjoy great autocompletions.
230230+We at [thundraa](https://thundraa.com) would be happy to help any open source CLI utility adopt tab.
231231+If you maintain a CLI and would like autocompletions set up for your users, just [drop the details in our _Adopting tab_ discussion](https://github.com/bombshell-dev/tab/discussions/61).
232232+We’ll gladly help and even open a PR to get you started.