You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+52-15Lines changed: 52 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,13 +3,15 @@
3
3
4
4
# tab
5
5
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`.
7
9
8
10
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.
9
11
10
12
Tab solves this complexity by providing autocompletions that work consistently across `zsh`, `bash`, `fish`, and `powershell`.
11
13
12
-
###Installation
14
+
## Installation
13
15
14
16
```bash
15
17
npm install @bomb.sh/tab
@@ -21,9 +23,50 @@ yarn add @bomb.sh/tab
21
23
bun add @bomb.sh/tab
22
24
```
23
25
24
-
### Package Manager Completions
26
+
## Quick Start
27
+
28
+
Add autocompletions to your CLI tool:
29
+
30
+
```typescript
31
+
importtfrom'@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:
25
61
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:
27
70
28
71
```bash
29
72
# this generates a completion script for your shell
@@ -33,23 +76,19 @@ npx @bomb.sh/tab yarn fish > ~/.config/fish/completions/yarn.fish
33
76
npx @bomb.sh/tab bun powershell >>$PROFILE
34
77
```
35
78
36
-
You'd get completions for all commands and options, and dynamic option values e.g., `--reporter=<TAB>`.
0 commit comments