@@ -2,20 +2,14 @@ def --env "nu-complete jc" [commandline: string] {
22 let stor = stor open
33
44 if $stor.jc_completions ? == null {
5- stor create -- table-name jc_completions -- columns { value : str , description: str }
5+ stor create -- table-name jc_completions -- columns { value : str , description: str , is_flag: bool }
66 }
77
88 if $stor.jc_completions_ran ? == null {
99 stor create -- table-name jc_completions_ran -- columns { _ : bool }
1010 }
1111
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 {
12+ if $stor.jc_completions_ran == [] { try {
1913 let about = ^ jc -- about
2014 | from json
2115
@@ -46,20 +40,25 @@ def --env "nu-complete jc" [commandline: string] {
4640 }
4741 | flatten
4842
49- $magic ++ if ($commandline | str ends-with " -" ) {
50- $options ++ $inherent
51- } else {
52- []
43+ for entry in $magic {
44+ stor insert -- table-name jc_completions -- data-record ($entry | insert is_flag false )
5345 }
54- } catch {
55- []
56- }
5746
58- for entry in $completions {
59- stor insert -- table-name jc_completions -- data-record $entry
60- }
47+ for entry in ($options ++ $inherent ) {
48+ stor insert -- table-name jc_completions -- data-record ($entry | insert is_flag true )
49+ }
50+
51+ stor insert -- table-name jc_completions_ran -- data-record { _ : true }
52+ } }
6153
62- $completions
54+ let show_flags = $commandline | str ends-with " -"
55+
56+ if $show_flags {
57+ $stor.jc_completions
58+ } else {
59+ $stor.jc_completions
60+ | where is_flag == 0
61+ } | select value description
6362}
6463
6564# Run `jc` (JSON Converter).
0 commit comments