diff --git a/modules/common/nushell/config.nu b/modules/common/nushell/config.nu index 482a816..4edf0fd 100644 --- a/modules/common/nushell/config.nu +++ b/modules/common/nushell/config.nu @@ -24,6 +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 + } + + let options = try { + let options = ^jc --help + | collect + | parse "{_}Parsers:\n{_}\n\nOptions:\n{inherent}\n\nSlice:{_}" + | get 0 + + let parsers = ^jc --about + | from json + | get parsers + | select argument description + | rename value description + + 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 { + [] + } + + $env.__NU_COMPLETE_JC = $options + + $options +} + +# Run `jc` (JSON Converter). +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: "jc exection failed" + label: { + text: ($run.stderr | str replace "jc:" "" | str replace "Error -" "" | str trim) + 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 @@ -295,9 +354,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 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