Skip to content

Commit 6ce9922

Browse files
committed
jc: cache completions
1 parent 0a36da8 commit 6ce9922

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

modules/jc/mod.nu

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
def --env "nu-complete jc" [commandline: string] {
2-
try {
2+
let stor = stor open
3+
4+
if $stor.jc_completions? == null {
5+
stor create --table-name jc_completions --columns { value: str, description: str }
6+
}
7+
8+
if $stor.jc_completions_ran? == null {
9+
stor create --table-name jc_completions_ran --columns { _: bool }
10+
}
11+
12+
if $stor.jc_completions_ran != [] {
13+
return $stor.jc_completions
14+
} else {
15+
stor insert --table-name jc_completions_ran --data-record { _: true }
16+
}
17+
18+
let completions = try {
319
let about = ^jc --about
420
| from json
521

@@ -38,6 +54,12 @@ def --env "nu-complete jc" [commandline: string] {
3854
} catch {
3955
[]
4056
}
57+
58+
for entry in $completions {
59+
stor insert --table-name jc_completions --data-record $entry
60+
}
61+
62+
$completions
4163
}
4264

4365
# Run `jc` (JSON Converter).

0 commit comments

Comments
 (0)