Open History to see the last commit
1import { readEnvironmentFromLoginShell, ShellEnvironmentReader } from "@t3tools/shared/shell";
2
3export function syncShellEnvironment(
4 env: NodeJS.ProcessEnv = process.env,
5 options: {
6 platform?: NodeJS.Platform;
7 readEnvironment?: ShellEnvironmentReader;
8 } = {},
9): void {
10 if ((options.platform ?? process.platform) !== "darwin") return;
11
12 try {
13 const shell = env.SHELL ?? "/bin/zsh";
14 const shellEnvironment = (options.readEnvironment ?? readEnvironmentFromLoginShell)(shell, [
15 "PATH",
16 "SSH_AUTH_SOCK",
17 ]);
18
19 if (shellEnvironment.PATH) {
20 env.PATH = shellEnvironment.PATH;
21 }
22
23 if (!env.SSH_AUTH_SOCK && shellEnvironment.SSH_AUTH_SOCK) {
24 env.SSH_AUTH_SOCK = shellEnvironment.SSH_AUTH_SOCK;
25 }
26 } catch {
27 // Keep inherited environment if shell lookup fails.
28 }
29}