From a8cec1de3c6cb449abbcc47dc15adc0524bf8361 Mon Sep 17 00:00:00 2001 From: RGBCube Date: Fri, 18 Jul 2025 21:06:52 +0300 Subject: [PATCH 1/4] nushell: add jc --- modules/common/nushell/config.nu | 21 +++++++++++++++++++++ modules/common/packages.nix | 1 + 2 files changed, 22 insertions(+) diff --git a/modules/common/nushell/config.nu b/modules/common/nushell/config.nu index 482a816..9a28cbf 100644 --- a/modules/common/nushell/config.nu +++ b/modules/common/nushell/config.nu @@ -24,6 +24,27 @@ def --env mcg [path: path]: nothing -> nothing { jj git init --colocate } +# Run `jc` (JSON Converter). +def --wrapped jc [...arguments]: [any -> table, any -> record, any -> string] { + let run = ^jc ...$arguments | complete + + if $run.exit_code != 0 { + error make { + msg: $run.stderr, + label: { + text: "jc execution failed", + span: (metadata $arguments).span + } + } + } + + if "--help" in $arguments or "-h" in $arguments { + $run.stdout + } else { + $run.stdout | from json + } +} + # `nu-highlight` with default colors # # Custom themes can produce a lot more ansi color codes and make the output diff --git a/modules/common/packages.nix b/modules/common/packages.nix index 38784a5..93bebad 100644 --- a/modules/common/packages.nix +++ b/modules/common/packages.nix @@ -14,6 +14,7 @@ in { fastfetch fd hyperfine + jc moreutils openssl p7zip From 9da7ad1439d7904ab3daa4c300950e5eafddbfc0 Mon Sep 17 00:00:00 2001 From: RGBCube Date: Fri, 18 Jul 2025 21:17:55 +0300 Subject: [PATCH 2/4] nushell: uncap ide suggestion width --- modules/common/nushell/config.nu | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/modules/common/nushell/config.nu b/modules/common/nushell/config.nu index 9a28cbf..7b112d5 100644 --- a/modules/common/nushell/config.nu +++ b/modules/common/nushell/config.nu @@ -30,9 +30,9 @@ def --wrapped jc [...arguments]: [any -> table, any -> record, any -> string] { if $run.exit_code != 0 { error make { - msg: $run.stderr, + msg: $run.stderr label: { - text: "jc execution failed", + text: "jc execution failed" span: (metadata $arguments).span } } @@ -316,9 +316,18 @@ let menus = [ marker: $env.PROMPT_INDICATOR type: { layout: ide - border: false - correct_cursor_pos: true + min_completion_width: 0 + max_completion_width: 150 max_completion_height: 25 + padding: 0 + border: false + cursor_offset: 0 + description_mode: "prefer_right" + min_description_width: 0 + max_description_width: 50 + max_description_height: 10 + description_offset: 1 + correct_cursor_pos: true } style: { text: white From fd49444afe4cdf2961d4c6a1a41fb033b827587e Mon Sep 17 00:00:00 2001 From: RGBCube Date: Fri, 18 Jul 2025 22:33:38 +0300 Subject: [PATCH 3/4] 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 } } From e3096645a875cd6960ed0fbd363f591c354e77fc Mon Sep 17 00:00:00 2001 From: RGBCube Date: Fri, 18 Jul 2025 22:43:39 +0300 Subject: [PATCH 4/4] nushell: fix jc completer --- modules/common/nushell/config.nu | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/modules/common/nushell/config.nu b/modules/common/nushell/config.nu index 1cc1ae3..4edf0fd 100644 --- a/modules/common/nushell/config.nu +++ b/modules/common/nushell/config.nu @@ -30,13 +30,16 @@ def --env "nu-complete jc" [] { } let options = try { - let options = jc --help - | parse "{_}Options:\n{inherent}\n\nSlice:{_}" + let options = ^jc --help + | collect + | parse "{_}Parsers:\n{_}\n\nOptions:\n{inherent}\n\nSlice:{_}" | get 0 - let parsers = jc --about + let parsers = ^jc --about | from json - | get parsers.argument + | get parsers + | select argument description + | rename value description let inherent = $options.inherent | lines @@ -51,7 +54,7 @@ def --env "nu-complete jc" [] { $parsers ++ $inherent } catch { - null + [] } $env.__NU_COMPLETE_JC = $options