diff --git a/src/vs/workbench/contrib/terminal/electron-browser/terminalInstanceService.ts b/src/vs/workbench/contrib/terminal/electron-browser/terminalInstanceService.ts index 45a5971aad9f2..e22c8b92540ab 100644 --- a/src/vs/workbench/contrib/terminal/electron-browser/terminalInstanceService.ts +++ b/src/vs/workbench/contrib/terminal/electron-browser/terminalInstanceService.ts @@ -98,10 +98,29 @@ export class TerminalInstanceService implements ITerminalInstanceService { this._mainProcessParentEnv = env; } - // For macOS just return the root environment which seems to always be {}, this is the - // parent of the main process when code is launched from the dock. + // For macOS it doesn't appear to be possible to get the "root" environment as + // `ps eww -o command` for PID 1 (the parent of the main process when launched from the + // dock/finder) returns no environment, because of this we will fill in the root environment + // using a whitelist of environment variables that we have. if (isMacintosh) { this._mainProcessParentEnv = {}; + // This list was generated by diffing launching a terminal with {} and the system + // terminal launched from finder. + const rootEnvVars = [ + 'SHELL', + 'SSH_AUTH_SOCK', + 'Apple_PubSub_Socket_Render', + 'XPC_FLAGS', + 'XPC_SERVICE_NAME', + 'HOME', + 'LOGNAME', + 'TMPDIR' + ]; + rootEnvVars.forEach(k => { + if (process.env[k]) { + this._mainProcessParentEnv![k] = process.env[k]!; + } + }); } // TODO: Windows should return a fresh environment block, might need native code?