-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
Locally exported environment variables are overwritten by ~/.bash_profile when using code .
#1033
Comments
After discovering that a doubly-clicked app on OSX would not inherit the users's shell environment we implemented the following: at startup, Code spawns the user's default shell, extracts its environment and sets that as its own. Let's call this process: ⚡. So, here's what's happening:
A possible fix would be to detect whether we are spawned via double-click or the |
@joaomoreno so are you proposing that we do the detection only when someone double clicks from the desktop but when running from the command line we don't do this because we assume the environment is correctly passed in? I think we only set VSCODE_CWD from the script so it is a fair guess to say that someone launched from the command line when this one is present. |
Sounds like a reasonable proposal to me. I'm wondering if that's what e.g. atom is doing? Because for atom the same setup works pretty well for me. |
+1, I'm currently trying to package EDIT1: Changing Object.assign(process.env, userEnv); to for (var userEnvKey in userEnv) {
if (!(userEnvKey in process.env))
process.env[userEnvKey] = userEnv[userEnvKey];
} should prevent overwriting of existing environment variables. EDIT2: |
@bpasero This is actually now trivial to implement, given the new cli launcher. We can simply prevent doing this when launching from it. 🎆 |
To verify on OS X:
|
As per https://github.com/Microsoft/vscode/blob/71f93aa38eed15c56d23845904e4dab245b86cc3/src/vs/workbench/electron-browser/main.ts#L53-L55 , need to set VSCODE_CLI=1 envvar to make this work. For example, using latest release:
The following still gets overwritten: GOPATH=/tmp code .
# shell's rc exports GOPATH=/something/different
# process.env.GOPATH=/something/different, not /tmp The following works as expected: GOPATH=/tmp VSCODE_CLI=1 code .
# even though shell's rc exports GOPATH=/something/different,
# process.env.GOPATH=/tmp |
We now set this variable in all places that code should launch from the command line. So, what is the full location of your global |
Using linux. > which vscode
/home/saml/bin/vscode
> file /home/saml/bin/vscode
/home/saml/bin/vscode: symbolic link to `/home/saml/opt/VSCode-linux-x64/code' Just noticed there's It feels like executing login shell behavior could be inverted: by default login shell isn't executed. But Mac OSX app launcher(?) would execute login shell if needed envvars aren't set. |
Try pointing the symlink at |
It's just that it's hard to identify when that situation occurs (double click on OS X, or Linux even). Yes, you should point to
|
That works. When I tested bin/code before, I had other vscode instances running |
Per microsoft/vscode-go#141, there appears to still be an issue with how env vars are passed into Code, even after the fix for #560.
Steps to reproduce:
export FOO=1
in your.bash_profile
code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $* ;}
export FOO=2
in your terminal sessioncode .
process.env["FOO"]
Expected:
Foo
should be2
Result:
FOO
will be1
But the thing that's really odd is that if you skip step (1) (remove this from you
.bash_profile
), you will seeFoo
set to2
. So in that case, the local environment is getting passed in.It seems like this must be either a problem with how vscode is setting up the env vars, or how
open
in OS X behaves.The text was updated successfully, but these errors were encountered: