mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-01 06:37:46 +00:00
jc: fix completions for flags
This commit is contained in:
parent
6ce9922b98
commit
d8b8b2cc80
1 changed files with 16 additions and 19 deletions
|
@ -2,20 +2,14 @@ def --env "nu-complete jc" [commandline: string] {
|
||||||
let stor = stor open
|
let stor = stor open
|
||||||
|
|
||||||
if $stor.jc_completions? == null {
|
if $stor.jc_completions? == null {
|
||||||
stor create --table-name jc_completions --columns { value: str, description: str }
|
stor create --table-name jc_completions --columns { value: str, description: str, is_flag: bool }
|
||||||
}
|
}
|
||||||
|
|
||||||
if $stor.jc_completions_ran? == null {
|
if $stor.jc_completions_ran? == null {
|
||||||
stor create --table-name jc_completions_ran --columns { _: bool }
|
stor create --table-name jc_completions_ran --columns { _: bool }
|
||||||
}
|
}
|
||||||
|
|
||||||
if $stor.jc_completions_ran != [] {
|
if $stor.jc_completions_ran == [] { try {
|
||||||
return $stor.jc_completions
|
|
||||||
} else {
|
|
||||||
stor insert --table-name jc_completions_ran --data-record { _: true }
|
|
||||||
}
|
|
||||||
|
|
||||||
let completions = try {
|
|
||||||
let about = ^jc --about
|
let about = ^jc --about
|
||||||
| from json
|
| from json
|
||||||
|
|
||||||
|
@ -46,20 +40,23 @@ def --env "nu-complete jc" [commandline: string] {
|
||||||
}
|
}
|
||||||
| flatten
|
| flatten
|
||||||
|
|
||||||
$magic ++ if ($commandline | str ends-with "-") {
|
for entry in $magic {
|
||||||
$options ++ $inherent
|
stor insert --table-name jc_completions --data-record ($entry | insert is_flag false)
|
||||||
} else {
|
|
||||||
[]
|
|
||||||
}
|
}
|
||||||
} catch {
|
|
||||||
[]
|
|
||||||
}
|
|
||||||
|
|
||||||
for entry in $completions {
|
for entry in ($options ++ $inherent) {
|
||||||
stor insert --table-name jc_completions --data-record $entry
|
stor insert --table-name jc_completions --data-record ($entry | insert is_flag true)
|
||||||
}
|
}
|
||||||
|
|
||||||
$completions
|
stor insert --table-name jc_completions_ran --data-record { _: true }
|
||||||
|
} }
|
||||||
|
|
||||||
|
if ($commandline | str contains "-") {
|
||||||
|
$stor.jc_completions
|
||||||
|
} else {
|
||||||
|
$stor.jc_completions
|
||||||
|
| where is_flag == 0
|
||||||
|
} | select value description
|
||||||
}
|
}
|
||||||
|
|
||||||
# Run `jc` (JSON Converter).
|
# Run `jc` (JSON Converter).
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue