Skip to content

Commit 78dfd04

Browse files
committed
Get mac launching with mostly root env
Part of #70248
1 parent ce84b4a commit 78dfd04

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/vs/workbench/contrib/terminal/electron-browser/terminalInstanceService.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,29 @@ export class TerminalInstanceService implements ITerminalInstanceService {
9898
this._mainProcessParentEnv = env;
9999
}
100100

101-
// For macOS just return the root environment which seems to always be {}, this is the
102-
// parent of the main process when code is launched from the dock.
101+
// For macOS it doesn't appear to be possible to get the "root" environment as
102+
// `ps eww -o command` for PID 1 (the parent of the main process when launched from the
103+
// dock/finder) returns no environment, because of this we will fill in the root environment
104+
// using a whitelist of environment variables that we have.
103105
if (isMacintosh) {
104106
this._mainProcessParentEnv = {};
107+
// This list was generated by diffing launching a terminal with {} and the system
108+
// terminal launched from finder.
109+
const rootEnvVars = [
110+
'SHELL',
111+
'SSH_AUTH_SOCK',
112+
'Apple_PubSub_Socket_Render',
113+
'XPC_FLAGS',
114+
'XPC_SERVICE_NAME',
115+
'HOME',
116+
'LOGNAME',
117+
'TMPDIR'
118+
];
119+
rootEnvVars.forEach(k => {
120+
if (process.env[k]) {
121+
this._mainProcessParentEnv![k] = process.env[k]!;
122+
}
123+
});
105124
}
106125

107126
// TODO: Windows should return a fresh environment block, might need native code?

0 commit comments

Comments
 (0)