From fd49444afe4cdf2961d4c6a1a41fb033b827587e Mon Sep 17 00:00:00 2001 From: RGBCube Date: Fri, 18 Jul 2025 22:33:38 +0300 Subject: [PATCH] nushell: make jc wrapper better --- modules/common/nushell/config.nu | 41 +++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/modules/common/nushell/config.nu b/modules/common/nushell/config.nu index 7b112d5..1cc1ae3 100644 --- a/modules/common/nushell/config.nu +++ b/modules/common/nushell/config.nu @@ -24,15 +24,50 @@ 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 + } + + let options = try { + let options = jc --help + | parse "{_}Options:\n{inherent}\n\nSlice:{_}" + | get 0 + + let parsers = jc --about + | from json + | get parsers.argument + + let inherent = $options.inherent + | lines + | parse " {short}, {long} {description}" + | update description { str trim } + | each {|record| + [[value, description]; + [$record.short, $record.description], + [$record.long, $record.description]] + } + | flatten + + $parsers ++ $inherent + } catch { + null + } + + $env.__NU_COMPLETE_JC = $options + + $options +} + # Run `jc` (JSON Converter). -def --wrapped jc [...arguments]: [any -> table, any -> record, any -> string] { +def --wrapped jc [...arguments: string@"nu-complete jc"]: [any -> table, any -> record, any -> string] { let run = ^jc ...$arguments | complete if $run.exit_code != 0 { error make { - msg: $run.stderr + msg: "jc exection failed" label: { - text: "jc execution failed" + text: ($run.stderr | str replace "jc:" "" | str replace "Error -" "" | str trim) span: (metadata $arguments).span } }