question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prepending PATH env var with environmentVariableCollection doesn't work on macOS

See original GitHub issue

This was covered a little bit in https://github.com/microsoft/vscode/issues/94153 but that issue is locked and can’t be discussed there. This feature feels pretty broken on macOS and I hope might be revisited.

The issue is on macOS prepending to PATH:

context.environmentVariableCollection.prepend("PATH", "/foo/my/path:");

This ends up being added to the end of the path, rather than the start. @Tyriar wrote up why this is in microsoft/vscode-docs@38653d4 and offered two workarounds, however neither of them are usable in my testing (as well as not really being feasible to tell all users to change):

  • "terminal.integrated.inheritEnv": false makes no difference at all, the PATH till is added to the end (this is a problem because the purpose of using prepend above is that we need to override any existing SDK on PATH with the one the user just selected)
  • "terminal.integrated.shellArgs": [] results in a completely empty PATH besides the values I’ve prepended, which means that pretty much everything else is missing and won’t work. This might be solvable by pushing process.env.PATH into environmentVariableCollection too, however the prompt to the user would look ridiculous as it would include their entire PATH

I appreciate this probably isn’t VS Code’s fault, but given macOS is fairly common and this behaviour seems to happen on a clean macOS install (it happens on both of mine, and I’ve customised almost nothing) it feels like it’s worth trying to fix (maybe even if it means sending export PATH=foo:$PATH once the shell is initialised? 😄).

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:24
  • Comments:15 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
DanTupcommented, Oct 24, 2022

Awesome, thanks! I’m definitely interested in testing this if/when there’s something more concrete 😃

1reaction
Tyriarcommented, Oct 24, 2022

@DanTup actually had a discussion with the Python team around this so I’m guessing this will get prioritized soon. The way I’m envisioning this working is for some environment variable being set (VSCODE_ENV_CONTRIBUTION or something?) and the shell integration script checking that and re-applying it after the init scripts run

Read more comments on GitHub >

github_iconTop Results From Across the Web

macos - Setting PATH environment variable in OSX permanently
I need a way to set these variables such that it won't require setting them again and again each time I open a...
Read more >
Use environment variables in Terminal on Mac - Apple Support
Environment variables are inherited by all commands executed in the shell's context, and some commands depend on environment variables. Open Terminal for me....
Read more >
Variables reference - Visual Studio Code
Variables Reference. Visual Studio Code supports variable substitution in Debugging and Task configuration files as well as some select settings.
Read more >
python unittest set environment variable - Gallarate Sposi
Sample Code: from unittest import TestCase, mock from path. ... Conclusion It's very easy to work with environment variables in Python. com/spulec/moto.
Read more >
How can I add a path to the PATH environment variable?
echo 'export PATH=/my/path:$PATH' >> ~/.bash_profile should do the trick! If you used echo 'export PATH=/my/path:$PATH' > ~/.bash_profile , or any such ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found