PATH is not set correctly in nushell
Describe the bug
This is technically two things, but both related to setting PATH in nushell. I have a fix locally, but am having some trouble getting the docker tasks to run, so opening an issue before I spend time on the tests.
If mise is not in the path when mise activate nu is run, it will prepend
$env.PATH = ($env.PATH | prepend $YOUR_MISE_PATH)
to the output. This causes an error
1 │ $env.PATH = ($env.PATH | prepend '/opt/homebrew/bin')
· ────┬────
· ╰── expected def, const, extern, alias, use, module, export or export-env keyword
The solution is to use export-env:
export-env { $env.PATH = ($env.PATH | prepend $YOUR_MISE_PATH) }
Related, the current method of setting PATH for installed tools breaks the table-like output expected in nu:
> $env.PATH
$HOME/Desktop/mise/target/debug:$HOME/.local/share/mise/installs/neovim/nightly/bin:$HOME/.local/share/mise/installs/node/latest/bin:$HOME/.local/share/mise/installs/go/1.22.3/bin:$HOME/.local/share/mise/installs/go/1.22.3/go/bin:$HOME/.local/share/mise/installs/usage/latest/bin:/opt/homebrew/bin:/opt/homebrew/sbin:$HOME/.cargo/bin:/usr/bin:/bin:/usr/sbin:/sbin
instead of
> $env.PATH
────┬─────────────────────────────────────────────────────
0 │ $HOME/Desktop/mise/target/debug
1 │ $HOME/.local/share/mise/installs/neovim/nightly/bin
2 │ $HOME/.local/share/mise/installs/node/latest/bin
3 │ $HOME/.local/share/mise/installs/go/1.22.3/bin
4 │ $HOME/.local/share/mise/installs/go/1.22.3/go/bin
5 │ $HOME/.local/share/mise/installs/usage/latest/bin
6 │ /opt/homebrew/bin
7 │ /opt/homebrew/sbin
8 │ $HOME/.cargo/bin
9 │ /usr/bin
10 │ /bin
11 │ /usr/sbin
12 │ /sbin
────┴─────────────────────────────────────────────────────
To Reproduce
- With
misenot in PATH, run the setup instructions here: https://mise.jdx.dev/getting-started.html#nushell, but make sure to use the full path tomise. - Run the
usecommand to load the module created above.
Expected behavior A clear and concise description of what you expected to happen.
mise doctor output
version: 2024.6.6 macos-arm64 (2024-06-20)
activated: yes
shims_on_path: no
build_info:
Target: aarch64-apple-darwin
Features: DEFAULT, NATIVE_TLS
Built: Thu, 20 Jun 2024 17:07:53 +0000
Rust Version: rustc 1.79.0 (129f3b996 2024-06-10) (Homebrew)
Profile: release
shell:
nu
0.94.2
dirs:
data: ~/.local/share/mise
config: ~/.config/mise
cache: ~/Library/Caches/mise
state: ~/.local/state/mise
shims: ~/.local/share/mise/shims
config_files:
~/.config/mise/config.toml
backends:
cargo
core
go
npm
pipx
spm
ubi
plugins:
bun (core)
deno (core)
erlang (core)
go (core)
java (core)
neovim https://github.com/richin13/asdf-neovim.git#d6118ad
node (core)
python (core)
ruby (core)
usage https://github.com/jdx/mise-usage.git#fe3888a
zig (core)
toolset:
neovim@nightly
[email protected]
[email protected]
[email protected]
env_vars:
MISE_SHELL=nu
settings:
activate_aggressive = false
all_compile = false
always_keep_download = false
always_keep_install = false
asdf_compat = true
cargo_binstall = true
color = true
disable_default_shorthands = false
disable_tools = []
experimental = true
go_default_packages_file = "~/.default-go-packages"
go_download_mirror = "https://dl.google.com/go"
go_repo = "https://github.com/golang/go"
go_set_gopath = false
go_set_goroot = true
go_skip_checksum = false
http_timeout = 30
jobs = 4
legacy_version_file = true
legacy_version_file_disable_tools = []
node_compile = false
not_found_auto_install = true
paranoid = false
plugin_autoupdate_last_check_duration = "7d"
python_default_packages_file = "/Users/username/.default-python-packages"
python_pyenv_repo = "https://github.com/pyenv/pyenv.git"
raw = false
trusted_config_paths = []
quiet = false
verbose = false
yes = false
ci = false
debug = false
trace = false
log_level = "info"
python_venv_auto_create = false
[status]
missing_tools = "if_other_versions_installed"
show_env = false
show_tools = false
No warnings found
1 problem found:
1. shims are missing, run mise reshim to create them
Missing shims: corepack, deno, go, gofmt, node, npm, npx, nvim, usage
Additional context There is a relatively simple fix to both items:
diff --git a/src/shell/nushell.rs b/src/shell/nushell.rs
index 5a32641b..ed365c3c 100644
--- a/src/shell/nushell.rs
+++ b/src/shell/nushell.rs
@@ -67,7 +67,11 @@ impl Shell for Nushell {
def --env "update-env" [] {{
for $var in $in {{
if $var.op == "set" {{
- load-env {{($var.name): $var.value}}
+ if $var.name == 'PATH' {{
+ $env.PATH = ($var.value | split row (char esep))
+ }} else {{
+ load-env {{($var.name): $var.value}}
+ }}
}} else if $var.op == "hide" {{
hide-env $var.name
}}
@@ -97,7 +101,7 @@ impl Shell for Nushell {
}
fn prepend_env(&self, k: &str, v: &str) -> String {
- format!("$env.{k} = ($env.{k} | prepend '{v}')\n")
+ format!("export-env {{ $env.{k} = ($env.{k} | prepend '{v}') }}\n")
}
fn unset_env(&self, k: &str) -> String {
Happy to open a PR if I can get the docker tasks to run.