1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-07-31 14:17:45 +00:00

jc: add magic command completions and clean up parsing

This commit is contained in:
RGBCube 2025-07-18 23:54:23 +03:00
parent 41b1e9510b
commit 9482d0325a
Signed by: RGBCube
SSH key fingerprint: SHA256:CzqbPcfwt+GxFYNnFVCqoN5Itn4YFrshg1TrnACpA5M

View file

@ -4,29 +4,37 @@ def --env "nu-complete jc" [] {
}
let options = try {
let options = ^jc --help
| collect
| parse "{_}Parsers:\n{_}\n\nOptions:\n{inherent}\n\nSlice:{_}"
| get 0
let parsers = ^jc --about
let about = ^jc --about
| from json
let magic = $about
| get parsers
| each { { value: $in.magic_commands?, description: $in.description } }
| where value != null
| flatten
let options = $about
| get parsers
| select argument description
| rename value description
let inherent = $options.inherent
let inherent = ^jc --help
| lines
| parse " {short}, {long} {description}"
| split list "" # Group with empty lines as boundary.
| where { $in.0? == "Options:" } | get 0 # Get the first section that starts with "Options:"
| skip 1 # Remove header
| each { str trim }
| parse "{short}, {long} {description}"
| update description { str trim }
| each {|record|
[[value, description];
[$record.short, $record.description],
[$record.long, $record.description]]
[$record.long, $record.description],
]
}
| flatten
$parsers ++ $inherent
$options ++ $inherent ++ $magic
} catch {
[]
}