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.2.md
+25-22Lines changed: 25 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,46 +2,48 @@
2
2
3
3
# tab
4
4
5
-
> Instant feedback for your CLI tool when hitting [TAB] in your terminal
5
+
> Instant feedback for your CLI tool when hitting [TAB] in your terminal
6
6
7
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 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.
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
13
```typescript
13
-
importtfrom'@bombsh/tab'
14
+
importtfrom'@bombsh/tab';
14
15
15
-
t.name('my-cli')
16
+
t.name('my-cli');
16
17
17
-
t.command('start', 'start the development server')
18
+
t.command('start', 'start the development server');
18
19
19
20
if (process.argv[2] ==='complete') {
20
-
const [shell, ...args] =process.argv.slice(3)
21
+
const [shell, ...args] =process.argv.slice(3);
21
22
if (shell==='--') {
22
-
t.parse(args)
23
+
t.parse(args);
23
24
} else {
24
-
t.setup(shell, x)
25
+
t.setup(shell, x);
25
26
}
26
27
}
27
28
```
28
29
29
-
This `my-cli.ts` would be equipped with all the tools required to provide autocompletions.
30
+
This `my-cli.ts` would be equipped with all the tools required to provide autocompletions.
30
31
31
32
```bash
32
33
node my-cli.ts complete -- "st"
33
34
```
35
+
34
36
```
35
37
start start the development server
36
38
:0
37
39
```
38
40
39
-
This output was generated by the `t.parse` method to autocomplete "st" to "start".
41
+
This output was generated by the `t.parse` method to autocomplete "st" to "start".
40
42
41
-
Obviously, the user won't be running that command directly in their terminal. They'd be running something like this.
43
+
Obviously, the user won't be running that command directly in their terminal. They'd be running something like this.
42
44
43
45
```bash
44
-
source<(node my-cli.ts complete zsh)
46
+
source<(node my-cli.ts complete zsh)
45
47
```
46
48
47
49
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`.
@@ -52,54 +54,55 @@ The autocompletions only live through the current shell session. To set them up
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.
63
+
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.
62
64
63
65
---
64
66
65
-
While working on tab, we came to the realization that most JavaScript CLIs are not global CLI commands but rather, per-project dependencies.
67
+
While working on tab, we came to the realization that most JavaScript CLIs are not global CLI commands but rather, per-project dependencies.
66
68
67
69
For instance, Vite won't be installed globally and instead it'd be always installed on a project. Here's an example usage:
68
70
69
71
```bash
70
72
pnpm vite dev
71
73
```
72
74
73
-
Rather than installing it globally. This example is pretty rare:
75
+
Rather than installing it globally. This example is pretty rare:
74
76
75
77
```bash
76
78
vite dev
77
79
```
78
80
79
-
So in this case, a computer might have hundreds of Vite instances each installed separately and potentially from different versions on different projects.
81
+
So in this case, a computer might have hundreds of Vite instances each installed separately and potentially from different versions on different projects.
80
82
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.
83
+
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.
82
84
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`.
85
+
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
86
85
-
They'd only have to run this command once and inject it in their shell config.
87
+
They'd only have to run this command once and inject it in their shell config.
86
88
87
89
```bash
88
90
npx @bombsh/tab pnpm zsh
89
91
```
90
92
91
93
These autocompletions on top of the normal autocompletions that these package managers provide are going to be way more powerful.
92
94
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.
95
+
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.
94
96
95
97
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.
96
98
97
99
```bash
98
100
pnpm my-cli complete --
99
101
```
102
+
100
103
```
101
104
start start the development server
102
105
:0
103
106
```
104
107
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.
108
+
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.
Copy file name to clipboardExpand all lines: README.md
-1Lines changed: 0 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,3 @@
1
-
2
1
# tab
3
2
4
3
Shell autocompletions are largely missing in the javascript cli ecosystem. This tool is an attempt to make autocompletions come out of the box for any cli tool.
Copy file name to clipboardExpand all lines: bin/completion-handlers.ts
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
// TODO: i do not see any completion functionality in this file. nothing is being provided for the defined commands of these package managers. this is a blocker for release. every each of them should be handled.
1
+
// TODO: i do not see any completion functionality in this file. nothing is being provided for the defined commands of these package managers. this is a blocker for release. every each of them should be handled.
2
2
import{Completion}from'../src/index.js';
3
3
import{execSync}from'child_process';
4
4
@@ -72,7 +72,7 @@ export function setupCompletionForPackageManager(
72
72
setupBunCompletions(completion);
73
73
}
74
74
75
-
// TODO: the core functionality of tab should have nothing related to package managers. even though completion is not there anymore, but this is something to consider.
75
+
// TODO: the core functionality of tab should have nothing related to package managers. even though completion is not there anymore, but this is something to consider.
0 commit comments