1
Fork 0
mirror of https://github.com/RGBCube/ncc synced 2025-07-28 10:37:44 +00:00

jc: improve suggestions

This commit is contained in:
RGBCube 2025-07-19 00:57:12 +03:00
parent 874471e1df
commit ab464ce6f1
Signed by: RGBCube
SSH key fingerprint: SHA256:CzqbPcfwt+GxFYNnFVCqoN5Itn4YFrshg1TrnACpA5M
2 changed files with 42 additions and 24 deletions

View file

@ -24,42 +24,65 @@ def --env mcg [path: path]: nothing -> nothing {
jj git init --colocate
}
def --env "nu-complete jc" [] {
if $env.__NU_COMPLETE_JC? != null {
return $env.__NU_COMPLETE_JC
def --env "nu-complete jc" [commandline: string] {
let stor = stor open
if $stor.jc_completions? == null {
stor create --table-name jc_completions --columns { value: str, description: str, is_flag: bool }
}
let options = try {
let options = ^jc --help
| collect
| parse "{_}Parsers:\n{_}\n\nOptions:\n{inherent}\n\nSlice:{_}"
| get 0
if $stor.jc_completions_ran? == null {
stor create --table-name jc_completions_ran --columns { _: bool }
}
let parsers = ^jc --about
if $stor.jc_completions_ran == [] { try {
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
} catch {
[]
}
for entry in $magic {
stor insert --table-name jc_completions --data-record ($entry | insert is_flag false)
}
$env.__NU_COMPLETE_JC = $options
for entry in ($options ++ $inherent) {
stor insert --table-name jc_completions --data-record ($entry | insert is_flag true)
}
$options
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).

View file

@ -123,13 +123,8 @@ def darwin-shadow-xcode-popup [] {
def darwin-set-zshrc [] {
print "setting zshrc..."
let nu_command = $"let usr_bin_index = $env.PATH
| enumerate
| where item == /usr/bin
| get 0.index;
let nu_command = $"let usr_bin_index = $env.PATH | enumerate | where item == /usr/bin | get 0.index;
$env.PATH = $env.PATH | insert $usr_bin_index ($shadow_path | path expand);
$env.SHELL = which nu | get 0.path" | str replace --all "\n" ""
let zshrc = $"exec nu --execute '($nu_command)'"