From 920d4905ecf1bc8fba6fb4117c409602a2db8f91 Mon Sep 17 00:00:00 2001 From: Maxim Uvarov Date: Wed, 31 Dec 2025 16:22:10 -0300 Subject: [PATCH 1/6] refactor: explore pipeline append vs spread operator Replace spread operator pattern with pipeline + append + pass-through. This iteration tests whether conditional list building reads better as a pipeline flow. Before: [...(if cond { [a b] } else { [] })] After: [] | if cond { append [a b] } else { } --- numd/commands.nu | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/numd/commands.nu b/numd/commands.nu index 472e858..7af3e7a 100644 --- a/numd/commands.nu +++ b/numd/commands.nu @@ -476,11 +476,10 @@ export def execute-intermediate-script [ use_host_config: bool # if true, load host's env, config, and plugin files ]: nothing -> string { let args = if $use_host_config { - [ - ...(if ($nu.env-path | path exists) { [--env-config $nu.env-path] } else { [] }) - ...(if ($nu.config-path | path exists) { [--config $nu.config-path] } else { [] }) - ...(if ($nu.plugin-path | path exists) { [--plugin-config $nu.plugin-path] } else { [] }) - ] + [] + | if ($nu.env-path | path exists) { append [--env-config $nu.env-path] } else { } + | if ($nu.config-path | path exists) { append [--config $nu.config-path] } else { } + | if ($nu.plugin-path | path exists) { append [--plugin-config $nu.plugin-path] } else { } } else { [-n] } From 7faed78350f5f6e5f91d1e735c8ea47d0c92ef2c Mon Sep 17 00:00:00 2001 From: Maxim Uvarov Date: Wed, 31 Dec 2025 16:27:49 -0300 Subject: [PATCH 2/6] refactor: explore data-first filtering approach Replace pipeline append with data-first approach: define all options upfront as a list of lists, then filter with each + compact. Before: [] | if cond { append [a b] } else { } After: [[a b] [c d]] | each {|i| if cond { $i } } | compact --- numd/commands.nu | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/numd/commands.nu b/numd/commands.nu index 7af3e7a..f5b124e 100644 --- a/numd/commands.nu +++ b/numd/commands.nu @@ -476,10 +476,13 @@ export def execute-intermediate-script [ use_host_config: bool # if true, load host's env, config, and plugin files ]: nothing -> string { let args = if $use_host_config { - [] - | if ($nu.env-path | path exists) { append [--env-config $nu.env-path] } else { } - | if ($nu.config-path | path exists) { append [--config $nu.config-path] } else { } - | if ($nu.plugin-path | path exists) { append [--plugin-config $nu.plugin-path] } else { } + [ + [--env-config $nu.env-path] + [--config $nu.config-path] + [--plugin-config $nu.plugin-path] + ] + | each {|i| if ($i.1 | path exists) { $i } } + | compact } else { [-n] } From e1002ccbe3b57f0040d7ed24df73a8e986715d0f Mon Sep 17 00:00:00 2001 From: Maxim Uvarov Date: Wed, 31 Dec 2025 16:57:25 -0300 Subject: [PATCH 3/6] refactor: replace each+if+compact with where Simplify filtering by using `where` instead of `each {if} | compact`. More declarative and idiomatic Nushell. Before: | each {|i| if ($i.1 | path exists) { $i } } | compact After: | where {|i| $i.1 | path exists } --- numd/commands.nu | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/numd/commands.nu b/numd/commands.nu index f5b124e..89246b3 100644 --- a/numd/commands.nu +++ b/numd/commands.nu @@ -481,8 +481,7 @@ export def execute-intermediate-script [ [--config $nu.config-path] [--plugin-config $nu.plugin-path] ] - | each {|i| if ($i.1 | path exists) { $i } } - | compact + | where {|i| $i.1 | path exists } } else { [-n] } From 07971a5ea47db3408b9e78c67e81f43bfc635cff Mon Sep 17 00:00:00 2001 From: Maxim Uvarov Date: Wed, 31 Dec 2025 17:01:38 -0300 Subject: [PATCH 4/6] refactor: add flatten for nested list result The where filter returns list of lists; add flatten to get flat args list. --- numd/commands.nu | 1 + 1 file changed, 1 insertion(+) diff --git a/numd/commands.nu b/numd/commands.nu index 89246b3..70b1eb4 100644 --- a/numd/commands.nu +++ b/numd/commands.nu @@ -482,6 +482,7 @@ export def execute-intermediate-script [ [--plugin-config $nu.plugin-path] ] | where {|i| $i.1 | path exists } + | flatten } else { [-n] } From df6155f9ee357fd8904116557e5b612d73fa691a Mon Sep 17 00:00:00 2001 From: Maxim Uvarov Date: Wed, 31 Dec 2025 17:02:54 -0300 Subject: [PATCH 5/6] refactor: remove unnecessary parentheses from external command External commands don't need wrapping parentheses when piped directly. Before: (^$nu.current-exe ...$args $script) After: ^$nu.current-exe ...$args $script --- numd/commands.nu | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numd/commands.nu b/numd/commands.nu index 70b1eb4..e1fdd44 100644 --- a/numd/commands.nu +++ b/numd/commands.nu @@ -487,7 +487,7 @@ export def execute-intermediate-script [ [-n] } - (^$nu.current-exe ...$args $intermed_script_path) + ^$nu.current-exe ...$args $intermed_script_path | if $print_block_results { tee { print } } else { } | complete | if $in.exit_code == 0 { From 6330838937b1fd67967737b1e43b1b87a8328163 Mon Sep 17 00:00:00 2001 From: claude Date: Thu, 1 Jan 2026 00:21:24 -0300 Subject: [PATCH 6/6] chore: update example outputs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .../numd_commands_explanations.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/z_examples/2_numd_commands_explanations/numd_commands_explanations.md b/z_examples/2_numd_commands_explanations/numd_commands_explanations.md index 1d7bdaa..e5ba54c 100644 --- a/z_examples/2_numd_commands_explanations/numd_commands_explanations.md +++ b/z_examples/2_numd_commands_explanations/numd_commands_explanations.md @@ -221,8 +221,8 @@ compute-change-stats $file $md_orig $md_res # => │ filename │ simple_markdown.md │ # => │ nushell_blocks │ 3 │ # => │ levenshtein_dist │ 248 │ -# => │ diff_lines │ --12 (-33.3%) │ -# => │ diff_words │ --24 (-30.8%) │ -# => │ diff_chars │ --163 (-32.5%) │ +# => │ diff_lines │ -12 (-33.3%) │ +# => │ diff_words │ -24 (-30.8%) │ +# => │ diff_chars │ -163 (-32.5%) │ # => ╰──────────────────┴────────────────────╯ ```