From 6ce9922b982498fef891dbba20a74dcdc6770837 Mon Sep 17 00:00:00 2001 From: RGBCube Date: Sat, 19 Jul 2025 00:19:59 +0300 Subject: [PATCH] jc: cache completions --- modules/jc/mod.nu | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/modules/jc/mod.nu b/modules/jc/mod.nu index 2a1241a..878c600 100644 --- a/modules/jc/mod.nu +++ b/modules/jc/mod.nu @@ -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).