1
Fork 0
mirror of https://github.com/RGBCube/ncc synced 2025-07-29 02:57: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 jj git init --colocate
} }
def --env "nu-complete jc" [] { def --env "nu-complete jc" [commandline: string] {
if $env.__NU_COMPLETE_JC? != null { let stor = stor open
return $env.__NU_COMPLETE_JC
if $stor.jc_completions? == null {
stor create --table-name jc_completions --columns { value: str, description: str, is_flag: bool }
} }
let options = try { if $stor.jc_completions_ran? == null {
let options = ^jc --help stor create --table-name jc_completions_ran --columns { _: bool }
| collect }
| parse "{_}Parsers:\n{_}\n\nOptions:\n{inherent}\n\nSlice:{_}"
| get 0
let parsers = ^jc --about if $stor.jc_completions_ran == [] { try {
let about = ^jc --about
| from json | from json
let magic = $about
| get parsers
| each { { value: $in.magic_commands?, description: $in.description } }
| where value != null
| flatten
let options = $about
| get parsers | get parsers
| select argument description | select argument description
| rename value description | rename value description
let inherent = $options.inherent let inherent = ^jc --help
| lines | 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 } | update description { str trim }
| each {|record| | each {|record|
[[value, description]; [[value, description];
[$record.short, $record.description], [$record.short, $record.description],
[$record.long, $record.description]] [$record.long, $record.description],
]
} }
| flatten | flatten
$parsers ++ $inherent for entry in $magic {
} catch { 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). # Run `jc` (JSON Converter).

View file

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