Commit 1bad87c
committed
feat(npm): auto-install shell completion on
New npm postinstall script (scripts/postinstall.js) that runs
after every
changed 2 packages in 2s. It detects
the user's shell from $SHELL (or defaults to PowerShell on
Windows) and installs the right completion script to the
standard auto-load location for that shell:
bash -> ~/.local/share/bash-completion/completions/ado
zsh -> ~/.zsh/completions/_ado (+ fpath/compinit in ~/.zshrc)
fish -> ~/.config/fish/completions/ado.fish
pwsh -> ~/.config/powershell/ado-completion.ps1
(+ . -source line in $PROFILE)
The script is idempotent: re-running just refreshes the
generated completion (regenerated on every ado upgrade, so
new subcommands get auto-discovered). The zsh/pwsh config
edits check for a marker line and skip if already configured.
Opt out with:
ADO_NO_COMPLETION=1 npm install -g @gilbertwong1996/ado
For testing, the script honors ADO_BIN env var (point at a
real binary) and falls back to the npm-resolved wrapper.
Bugs fixed in the completion generator along the way:
- Schema.build_tree/0 returns maps with atom keys; the
generators used string keys. Added a normalize/1 helper
that recurses through the tree, converting all keys to
strings. Without this, the generated scripts had empty
subcommand lists (matching nothing).
- Powershell's @ado_top = @("") emitted an empty string
instead of an empty array. Now emits @() for an empty
subcommand list.
Tests (scripts/test_postinstall.js, 5 cases):
- bash detection + XDG path
- zsh detection + .zshrc config edit
- fish detection + standard path
- ADO_NO_COMPLETION=1 skips cleanly
- Second run is idempotent (no duplicate config lines)1 parent 0f2023b commit 1bad87c
5 files changed
Lines changed: 511 additions & 7 deletions
File tree
- lib/ado_cli/cli
- npm/@gilbertwong1996-ado
- scripts
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
152 | 167 | | |
153 | 168 | | |
154 | 169 | | |
| |||
162 | 177 | | |
163 | 178 | | |
164 | 179 | | |
165 | | - | |
166 | | - | |
| 180 | + | |
167 | 181 | | |
168 | 182 | | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
173 | 187 | | |
174 | 188 | | |
175 | 189 | | |
| |||
439 | 453 | | |
440 | 454 | | |
441 | 455 | | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
442 | 462 | | |
443 | 463 | | |
444 | 464 | | |
| |||
448 | 468 | | |
449 | 469 | | |
450 | 470 | | |
451 | | - | |
| 471 | + | |
452 | 472 | | |
453 | 473 | | |
454 | 474 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
26 | 29 | | |
27 | 30 | | |
| 31 | + | |
28 | 32 | | |
29 | 33 | | |
30 | 34 | | |
| |||
0 commit comments