diff --git a/src/shell/nushell.rs b/src/shell/nushell.rs index fd4d7a84d8..1512d02928 100644 --- a/src/shell/nushell.rs +++ b/src/shell/nushell.rs @@ -27,30 +27,29 @@ 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 }} - }}]) - }} - }}) + 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" {{ diff --git a/src/shell/snapshots/mise__shell__nushell__tests__hook_init.snap b/src/shell/snapshots/mise__shell__nushell__tests__hook_init.snap index e5dd743fdc..f168a92649 100644 --- a/src/shell/snapshots/mise__shell__nushell__tests__hook_init.snap +++ b/src/shell/snapshots/mise__shell__nushell__tests__hook_init.snap @@ -4,30 +4,29 @@ expression: "nushell.activate(exe, \" --status\".into())" --- 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 } - }]) - } - }) + 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) { ^"/some/dir/mise" } else if ($command == "activate") { @@ -40,7 +39,7 @@ def --wrapped mise [command?: string, --help, ...rest: string] { ^"/some/dir/mise" $command ...$rest } } - + def --env "update-env" [] { for $var in $in { if $var.op == "set" {