Skip to content

Commit

Permalink
Refactor Nushell script
Browse files Browse the repository at this point in the history
  • Loading branch information
texastoland committed Mar 10, 2024
1 parent 5562fcf commit 6c90f5c
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions src/shell/nushell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 [path hook] {{
let path = $path | split row . | prepend hooks | into cell-path
let hooks = $env.config | get --ignore-errors $path | default []
$env.config = ($env.config | upsert $path ($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") {{
Expand All @@ -63,7 +62,7 @@ impl Shell for Nushell {
^"{exe}" $command ...$rest
}}
}}
def --env "update-env" [] {{
for $var in $in {{
if $var.op == "set" {{
Expand Down

0 comments on commit 6c90f5c

Please sign in to comment.