From e47d85725f919f92434d926cb7a72555d82a7525 Mon Sep 17 00:00:00 2001 From: Texas Toland Date: Sun, 10 Mar 2024 13:24:41 -0500 Subject: [PATCH] Refactor Nushell script Rename Nushell param based on core team feedback --- src/shell/nushell.rs | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/src/shell/nushell.rs b/src/shell/nushell.rs index fd4d7a84d8..8416473f3e 100644 --- a/src/shell/nushell.rs +++ b/src/shell/nushell.rs @@ -26,31 +26,30 @@ impl Shell for Nushell { formatdoc! {r#" export-env {{ - $env.MISE_SHELL = "nu" - - $env.config = ($env.config | upsert hooks {{ - pre_prompt: ($env.config.hooks.pre_prompt ++ - [{{ - condition: {{|| "MISE_SHELL" in $env }} - code: {{|| mise_hook }} - }}]) - env_change: {{ - PWD: ($env.config.hooks.env_change.PWD ++ - [{{ - condition: {{|| "MISE_SHELL" in $env }} - code: {{|| mise_hook }} - }}]) - }} - }}) + load-env {{ MISE_SHELL: "nu" }} + add-hook pre_prompt {{ + condition: {{ "MISE_SHELL" in $env }} + code: {{ mise_hook }} + }} + add-hook env_change.PWD {{ + condition: {{ "MISE_SHELL" in $env }} + code: {{ mise_hook }} + }} + }} + + def --env add-hook [field hook] {{ + let field = $field | split row . | prepend hooks | into cell-path + let hooks = $env.config | get --ignore-errors $field | default [] + $env.config = ($env.config | upsert $field ($hooks ++ $hook)) }} - + def "parse vars" [] {{ $in | lines | parse "{{op}},{{name}},{{value}}" }} - - def --wrapped mise [command?: string, --help, ...rest: string] {{ + + export def --wrapped main [command?: string, --help, ...rest: string] {{ let commands = ["shell", "deactivate"] - + if ($command == null) {{ ^"{exe}" }} else if ($command == "activate") {{ @@ -63,7 +62,7 @@ impl Shell for Nushell { ^"{exe}" $command ...$rest }} }} - + def --env "update-env" [] {{ for $var in $in {{ if $var.op == "set" {{