36 lines · 947 B · TypeScript
RawDownload
import {  readEnvironmentFromLoginShell,  resolveLoginShell,  ShellEnvironmentReader,} from "@t3tools/shared/shell"; export function syncShellEnvironment(  env: NodeJS.ProcessEnv = process.env,  options: {    platform?: NodeJS.Platform;    readEnvironment?: ShellEnvironmentReader;  } = {},): void {  const platform = options.platform ?? process.platform;  if (platform !== "darwin" && platform !== "linux") return;   try {    const shell = resolveLoginShell(platform, env.SHELL);    if (!shell) return;     const shellEnvironment = (options.readEnvironment ?? readEnvironmentFromLoginShell)(shell, [      "PATH",      "SSH_AUTH_SOCK",    ]);     if (shellEnvironment.PATH) {      env.PATH = shellEnvironment.PATH;    }     if (!env.SSH_AUTH_SOCK && shellEnvironment.SSH_AUTH_SOCK) {      env.SSH_AUTH_SOCK = shellEnvironment.SSH_AUTH_SOCK;    }  } catch {    // Keep inherited environment if shell lookup fails.  }}