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
> a video showcasing how pnpm autocompletions works on a test cli command like `my-cli`
1
+
> A video showcasing how pnpm autocompletions work on a test CLI command like `my-cli`
2
2
3
3
# tab
4
4
5
-
> instant feedback when hitting [TAB] in your cli tool
5
+
> Instant feedback for your CLI tool when hitting [TAB] in your terminal
6
6
7
-
as cli tooling authors, if we can spare our users a second or two by not checking the documentation or writing the `-h` option, we're doing them a huge favor. the unconscious loves hitting the [TAB] key. it always expects feedback. so it feels dissappointing when hitting that key in the terminal but then nothing happens. that frustration is apparent across the whole javascript cli tooling ecosystem.
7
+
As CLI tooling authors, if we can spare our users a second or two by not checking the documentation or writing the `-h` option, we're doing them a huge favor. The unconscious loves hitting the [TAB] key. It always expects feedback. So it feels disappointing when hitting that key in the terminal but then nothing happens. That frustration is apparent across the whole JavaScript CLI tooling ecosystem.
8
8
9
-
autocompletions are the solution to not break the user's flow. the issue is they're not simple to add. `zsh` expects them in a way, and `bash` in another way. then where do we provide them so the shell environment parses them? too many headaches to ease the user's experience. whether it's worth it or not is out of the question. because tab is the solution to this complexity.
9
+
Autocompletions are the solution to not break the user's flow. The issue is they're not simple to add. `zsh` expects them in one way, and `bash` in another way. Then where do we provide them so the shell environment parses them? Too many headaches to ease the user's experience. Whether it's worth it or not is out of the question. Because tab is the solution to this complexity.
10
10
11
11
`my-cli.ts`:
12
12
```typescript
@@ -26,7 +26,7 @@ if (process.argv[2] === 'complete') {
26
26
}
27
27
```
28
28
29
-
this`my-cli.ts` would be equipped with all the tools required to provide autocompletions.
29
+
This`my-cli.ts` would be equipped with all the tools required to provide autocompletions.
30
30
31
31
```bash
32
32
node my-cli.ts complete -- "st"
@@ -36,57 +36,70 @@ start start the development server
36
36
:0
37
37
```
38
38
39
-
this output was generated by the `t.parse` method to autocomplete "st" to "start".
39
+
This output was generated by the `t.parse` method to autocomplete "st" to "start".
40
40
41
-
obviously, the user won't be running that command directly in their terminal. they'd be running something like this.
41
+
Obviously, the user won't be running that command directly in their terminal. They'd be running something like this.
42
42
43
43
```bash
44
44
source<(node my-cli.ts complete zsh)
45
45
```
46
46
47
-
now whenever the shell sees `my-cli`, it would bring the autocompletions we wrote for this cli tool. the`node my-cli.ts complete zsh` part would output the zsh script that loads the autocompletions provided by `t.parse` which then would be executed using `source`.
47
+
Now whenever the shell sees `my-cli`, it would bring the autocompletions we wrote for this CLI tool. The`node my-cli.ts complete zsh` part would output the zsh script that loads the autocompletions provided by `t.parse` which then would be executed using `source`.
48
48
49
-
the autocompletions are only lived through the current session. to set them up across all of terminal sessions, the autocompletion script should be injected in the `.zshrc` file.
49
+
The autocompletions only live through the current shell session. To set them up across all terminal sessions, the autocompletion script should be injected in the `.zshrc` file.
this is an example of autocompletions on a global cli command that is usually installed using the `-g` flag (e.g. `npm add -g my-cli`) which is available across the computer.
This is an example of autocompletions on a global CLI command that is usually installed using the `-g` flag (e.g. `npm add -g my-cli`) which is available across the computer.
56
62
57
63
---
58
64
59
-
while working on tab, we came to the realization that most javascript clis are not global cli commands but rather, per-project dependencies.
65
+
While working on tab, we came to the realization that most JavaScript CLIs are not global CLI commands but rather, per-project dependencies.
60
66
61
-
for instance, vite won't be installed globally and instead it'd be always installed on a project. here's an example usage:
67
+
For instance, Vite won't be installed globally and instead it'd be always installed on a project. Here's an example usage:
62
68
63
69
```bash
64
-
pnpm vite -h
70
+
pnpm vite dev
65
71
```
66
72
67
-
so in this case, a computer might have hundreds of vite instances each installed separately and potentially from different versions on different projects.
73
+
Rather than installing it globally. This example is pretty rare:
68
74
69
-
we were looking for a fluid strategy that would be able to load the autocompletions from each of these dependencies on a per-project basis.
75
+
```bash
76
+
vite dev
77
+
```
78
+
79
+
So in this case, a computer might have hundreds of Vite instances each installed separately and potentially from different versions on different projects.
70
80
71
-
and that made us develop our own autocompletion abstraction over npm, pnpm and yarn. this would help tab identify which binaries are avaialble in a project and which of these binaries provide autocompletions. so the user would not have to `source` anything or inject any script in their `.zshrc`.
81
+
We were looking for a fluid strategy that would be able to load the autocompletions from each of these dependencies on a per-project basis.
72
82
73
-
they'd only have to run this command once and inject it in their shell config.
83
+
And that made us develop our own autocompletion abstraction over npm, pnpm and yarn. This would help tab identify which binaries are available in a project and which of these binaries provide autocompletions. So the user would not have to `source` anything or inject any script in their `.zshrc`.
84
+
85
+
They'd only have to run this command once and inject it in their shell config.
These autocompletions on top of the normal autocompletions that these package managers provide are going to be way more powerful.
80
92
81
-
```typescript
82
-
importtfrom'@bombsh/tab'
83
-
84
-
t.option('help', 'list available commands') // Command (Root)
93
+
These new autocompletions on top of package managers would help us with autocompletions on commands like `pnpm vite` and other global or per-project binaries. The only requirement would be that the npm binary itself would be a tab-compatible binary.
85
94
86
-
t.command('start', 'start the development server') // Command ('start')
87
-
.option('port', 'specify the port number') // Command ('port')
95
+
What is a tab-compatible binary? It's a tool that provides the `complete` subcommand that was showcased above. Basically any CLI tool that uses tab for its autocompletions is a tab-compatible binary.
88
96
89
-
t.parse(process.argv.slice(3))
97
+
```bash
98
+
pnpm my-cli complete --
99
+
```
100
+
```
101
+
start start the development server
102
+
:0
103
+
```
90
104
91
-
t.setup(process.argv[2], x)
92
-
```
105
+
We are planning to maintain these package manager autocompletions on our own and turn them into full-fledged autocompletions that touch on every part of our package managers.
0 commit comments