Skip to content

Commit 2e1424f

Browse files
committed
update
1 parent a0a4b25 commit 2e1424f

File tree

1 file changed

+52
-15
lines changed

1 file changed

+52
-15
lines changed

README.md

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
44
# tab
55

6-
Shell autocompletions are largely missing in the JavaScript CLI ecosystem. This tool bridges that gap by autocompletions for `pnpm`, `npm`, `yarn`, and `bun` with dynamic option parsing and context-aware suggestions and also Easy-to-use adapters for popular JavaScript CLI frameworks like CAC, Citty, and Commander.js
6+
Shell autocompletions are largely missing in the JavaScript CLI ecosystem. Tab provides a simple API for adding autocompletions to any JavaScript CLI tool.
7+
8+
Additionally, tab supports autocompletions for `pnpm`, `npm`, `yarn`, and `bun`.
79

810
As 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.
911

1012
Tab solves this complexity by providing autocompletions that work consistently across `zsh`, `bash`, `fish`, and `powershell`.
1113

12-
### Installation
14+
## Installation
1315

1416
```bash
1517
npm install @bomb.sh/tab
@@ -21,9 +23,50 @@ yarn add @bomb.sh/tab
2123
bun add @bomb.sh/tab
2224
```
2325

24-
### Package Manager Completions
26+
## Quick Start
27+
28+
Add autocompletions to your CLI tool:
29+
30+
```typescript
31+
import t from '@bomb.sh/tab';
32+
33+
// Define your CLI structure
34+
t.command('dev', 'Start development server');
35+
t.option('port', 'Specify port', (complete) => {
36+
complete('3000', 'Development port');
37+
complete('8080', 'Production port');
38+
});
39+
40+
// Handle completion requests
41+
if (process.argv[2] === 'complete') {
42+
const shell = process.argv[3];
43+
if (shell === '--') {
44+
const args = process.argv.slice(4);
45+
t.parse(args);
46+
} else {
47+
t.setup('my-cli', 'node my-cli.js', shell);
48+
}
49+
}
50+
```
51+
52+
Test your completions:
53+
54+
```bash
55+
node my-cli.js complete -- dev --port=<TAB>
56+
# Output: --port=3000 Development port
57+
# --port=8080 Production port
58+
```
59+
60+
Install for users:
2561

26-
Get autocompletions for your package manager with zero configuration:
62+
```bash
63+
source <(my-cli complete zsh) # One-time setup
64+
my-cli complete zsh >> ~/.zshrc # Permanent setup
65+
```
66+
67+
## Package Manager Completions
68+
69+
As mentioned earlier, tab provides completions for package managers as well:
2770

2871
```bash
2972
# this generates a completion script for your shell
@@ -33,23 +76,19 @@ npx @bomb.sh/tab yarn fish > ~/.config/fish/completions/yarn.fish
3376
npx @bomb.sh/tab bun powershell >> $PROFILE
3477
```
3578

36-
You'd get completions for all commands and options, and dynamic option values e.g., `--reporter=<TAB>`.
37-
**Example in action:**
79+
Example in action:
3880

3981
```bash
4082
pnpm install --reporter=<TAB>
41-
# Shows append-only, default, ndjson, silent
42-
43-
npm remove <TAB>
44-
# Shows the packages from package.json
83+
# Shows: append-only, default, ndjson, silent (with descriptions)
4584

4685
yarn add --emoji=<TAB>
47-
# Show true, false
86+
# Shows: true, false
4887
```
4988

50-
### CLI Framework Integration
89+
## Framework Integration
5190

52-
For your own CLI tools, tab provides integration with popular frameworks:
91+
Tab includes adapters for popular JavaScript CLI frameworks:
5392

5493
#### Using the Core API
5594

@@ -205,8 +244,6 @@ for (const command of completion.commands.values()) {
205244
program.parse();
206245
```
207246

208-
Tab's package manager completions are dynamically generated from the actual help output of each tool:
209-
210247
Tab uses a standardized completion protocol that any CLI can implement:
211248

212249
```bash

0 commit comments

Comments
 (0)