1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-01 06:37:46 +00:00

jc: cache completions

This commit is contained in:
RGBCube 2025-07-19 00:19:59 +03:00
parent 0a36da8326
commit 6ce9922b98
Signed by: RGBCube
SSH key fingerprint: SHA256:CzqbPcfwt+GxFYNnFVCqoN5Itn4YFrshg1TrnACpA5M

View file

@ -1,5 +1,21 @@
def --env "nu-complete jc" [commandline: string] {
try {
let stor = stor open
if $stor.jc_completions? == null {
stor create --table-name jc_completions --columns { value: str, description: str }
}
if $stor.jc_completions_ran? == null {
stor create --table-name jc_completions_ran --columns { _: bool }
}
if $stor.jc_completions_ran != [] {
return $stor.jc_completions
} else {
stor insert --table-name jc_completions_ran --data-record { _: true }
}
let completions = try {
let about = ^jc --about
| from json
@ -38,6 +54,12 @@ def --env "nu-complete jc" [commandline: string] {
} catch {
[]
}
for entry in $completions {
stor insert --table-name jc_completions --data-record $entry
}
$completions
}
# Run `jc` (JSON Converter).