Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

env._.source scripts should be able to modify the PATH #3646

Closed
Mossop opened this issue Dec 17, 2024 · 3 comments · Fixed by #3685
Closed

env._.source scripts should be able to modify the PATH #3646

Mossop opened this issue Dec 17, 2024 · 3 comments · Fixed by #3685
Labels

Comments

@Mossop
Copy link

Mossop commented Dec 17, 2024

Describe the bug
A shell script sources by env._.source cannot modify the PATH environment variable.

To Reproduce

In a new directory:
Create a test.sh file:

export PATH="/Users/dave/test:$PATH"
export FOO_TEST="bar"

and a .mise.toml:

[env]
_.source = "test.sh"

Expected behavior
The FOO_TEST environment variable should be set and the change should be made to the PATH environment variable but only the first happens.

mise doctor output

version: 2024.12.12 macos-arm64 (2d9d289 2024-12-16)
activated: yes
shims_on_path: no

build_info:
  Target: aarch64-apple-darwin
  Features: DEFAULT, NATIVE_TLS, OPENSSL
  Built: Mon, 16 Dec 2024 18:21:21 +0000
  Rust Version: rustc 1.83.0 (90b35a623 2024-11-26)
  Profile: release

shell:
  /opt/homebrew/bin/bash
  GNU bash, version 5.2.37(1)-release (aarch64-apple-darwin24.0.0)
  Copyright (C) 2022 Free Software Foundation, Inc.
  License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

  This is free software; you are free to change and redistribute it.
  There is NO WARRANTY, to the extent permitted by law.

dirs:
  cache: ~/Library/Caches/mise
  config: ~/.config/mise
  data: ~/.local/share/mise
  shims: ~/.local/share/mise/shims
  state: ~/.local/state/mise

config_files:
  ~/.mise.toml
  ~/test/.mise.toml

backends:
  aqua
  asdf
  cargo
  core
  gem
  go
  npm
  pipx
  spm
  ubi
  vfox

plugins:

toolset:

path:
  ~/bin
  ~/.local/bin
  ~/dotfiles/platforms/macos/bin
  ~/dotfiles/bin
  /Applications/Visual Studio Code.app/Contents/Resources/app/bin
  /opt/homebrew/opt/curl/bin
  /opt/homebrew/opt/coreutils/libexec/gnubin
  /opt/homebrew/opt/grep/libexec/gnubin
  /opt/homebrew/opt/gnu-tar/libexec/gnubin
  /opt/homebrew/opt/gnu-sed/libexec/gnubin
  /opt/homebrew/opt/findutils/libexec/gnubin
  /opt/homebrew/opt/gnu-which/libexec/gnubin
  /opt/homebrew/bin
  /opt/homebrew/sbin
  /usr/local/bin
  /System/Cryptexes/App/usr/bin
  /usr/bin
  /bin
  /usr/sbin
  /sbin
  /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin
  /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin
  /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin
  ~/.atuin/bin
  ~/.cargo/bin

env_vars:
  MISE_SHELL=bash

settings:
  experimental       true ~/.mise.toml
  status.show_tools  true ~/.mise.toml

No problems found```

**Additional context**

@Mossop Mossop added the bug label Dec 17, 2024
@jdx
Copy link
Owner

jdx commented Dec 17, 2024

I believe you can but it may not be documented since this was something I needed for unrelated things in mise's internals I never intended to expose—except to possibly plugin devs.

You can set MISE_ADD_PATH which will be inserted at the beginning. There is also MISE_RM_PATH. Removals are something idk if I ever actually do in mise so removing may not work at all.

There is logic in mise to diff 2 PATH variables so this could also work in the way you're expecting, but since I only needed this for internal logic it wasn't necessary at the time to put the diffing into _.source.

I also kind of prefer _.source since if you do something crazy with PATH the diffing logic could fail or maybe even do something you definitely didn't want. 9/10 times though people just insert at the front though. Maybe more like 99/100.

@Mossop
Copy link
Author

Mossop commented Dec 17, 2024

I just tried with export MISE_ADD_PATH="..." and all it did was add that as an environment variable.

@jdx
Copy link
Owner

jdx commented Dec 18, 2024

alright thanks for checking, I think this should work the way you originally expected by modifying PATH directly

jdx added a commit that referenced this issue Dec 18, 2024
jdx added a commit that referenced this issue Dec 18, 2024
jdx added a commit that referenced this issue Dec 18, 2024
jdx added a commit that referenced this issue Dec 18, 2024
jdx added a commit that referenced this issue Dec 18, 2024
jdx added a commit that referenced this issue Dec 18, 2024
jdx added a commit that referenced this issue Dec 18, 2024
@jdx jdx closed this as completed in #3685 Dec 18, 2024
@jdx jdx closed this as completed in 1072132 Dec 18, 2024
miguelmig pushed a commit to miguelmig/mise that referenced this issue Dec 21, 2024
* fix: trap panics in task resolving

* feat: allow inserting PATH in env._.source

Fixes jdx#3646
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants