Commit 2aa7df8
fix(spec): catch duplicate registrations; feat(cd): complete from zoxide (#105)
Two fixes, independent of #103 and #104.
---
## 1. `Register` silently overwrites, and `find` was defined twice
`Register` is `Registry[s.Name] = s`, and every spec registers from an
`init()` spread across the `commands` packages. A name defined twice is
therefore resolved by package init order, and nothing anywhere reports
it.
`find` was registered in both `commands/fs/find.go` and
`commands/text/find.go`. The definitions are not equivalent — the `text`
one carries `FileGenerator("/")` and 26 options, the `fs` one has four
BSD-specific flags and no generator — so which one you got determined
whether `find` completed paths at all. Neither file gives any hint that
the other exists.
Merged into one: the BSD flags move onto the richer `text` definition
and the `fs` copy is removed. `Register` now records names it has seen
before, and a registry-wide test asserts there are none. Confirmed the
guard fails when a duplicate is reintroduced, rather than passing
vacuously.
## 2. `cd` could only complete children of the current directory
`cd` completes through `FileGenerator`, which reads exactly one
directory: the one you are standing in. So `cd proj` resolves only when
`proj` happens to be a child of the current directory, and returns
nothing at all otherwise — including for directories visited many times
a day.
That is close to the opposite of what `cd` is normally reached for, and
from the prompt it does not read as a scope limit; it reads as
completion being broken, because nothing appears.
`zoxide.extend-cd` routes `cd` through the generator `z` already uses,
so local children are offered first and zoxide's frecency database
supplies everything else:
```
# in ~/dotfiles
cd Develop -> ~/Development, ~/Developer, ~/Development/cnc-claims, ...
cd conf -> config/ (local child, still first), then ~/.config, ~/dotfiles/.config
```
Off by default. It shells out to zoxide, and offering absolute paths
from outside the current directory is a real change in what `cd`
proposes.
### The query is now cached
`zoxide query -l` is a subprocess costing ~11ms on this machine, and
generators run on **every keystroke** — that is the entire budget for a
suggestion redraw. The result is cached for two seconds; the list only
changes when the user changes directory, so the window costs nothing in
practice.
This applies to `z` and `zi` as well, which were paying that cost per
keystroke already.
---
## Testing
`go test -race ./...` passes.
Behaviour was checked by driving the built binary through a real pty
against an unmodified interactive zsh (starship, zsh-autosuggestions,
fzf-tab, atuin loaded), reading the byte stream rather than trusting
unit tests alone — the `cd Develop` and `cd conf` results above are
transcribed from that.
No new dependencies.
---------
Co-authored-by: verse91 <versedev.store@proton.me>1 parent 83056ba commit 2aa7df8
11 files changed
Lines changed: 126 additions & 29 deletions
File tree
- commands
- fs
- text
- internal/config
- root
- spec
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
330 | 330 | | |
331 | 331 | | |
332 | 332 | | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
333 | 336 | | |
334 | 337 | | |
335 | 338 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
15 | 24 | | |
16 | 25 | | |
17 | 26 | | |
| |||
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
13 | 15 | | |
14 | 16 | | |
15 | 17 | | |
| |||
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
33 | 77 | | |
34 | 78 | | |
35 | 79 | | |
36 | 80 | | |
37 | 81 | | |
38 | 82 | | |
39 | | - | |
40 | | - | |
| 83 | + | |
41 | 84 | | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | 85 | | |
52 | 86 | | |
53 | 87 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
13 | 20 | | |
14 | 21 | | |
15 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
106 | 121 | | |
107 | 122 | | |
108 | 123 | | |
| |||
152 | 167 | | |
153 | 168 | | |
154 | 169 | | |
| 170 | + | |
155 | 171 | | |
156 | 172 | | |
157 | 173 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
50 | 53 | | |
51 | 54 | | |
52 | 55 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
114 | 119 | | |
115 | 120 | | |
116 | 121 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
296 | 296 | | |
297 | 297 | | |
298 | 298 | | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
299 | 304 | | |
300 | 305 | | |
301 | 306 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
3 | 5 | | |
4 | 6 | | |
5 | 7 | | |
| |||
46 | 48 | | |
47 | 49 | | |
48 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
49 | 60 | | |
50 | 61 | | |
51 | 62 | | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
52 | 66 | | |
53 | 67 | | |
54 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
55 | 76 | | |
56 | 77 | | |
57 | 78 | | |
| 79 | + | |
58 | 80 | | |
0 commit comments