Elffuss BraidHub

kikocis/continue public

d4c11b015258 · 828 BRawPermalink
1import { execSync } from "child_process";
2
3/**
4 * Gets the PATH env var from the user's login shell on non-Windows platforms.
5 * Windows is not implemented primarily because it is not needed at the moment.
6 * @returns The enhanced PATH from the user's shell, or the current PATH if it cannot be determined
7 */
8export function getEnvPathFromUserShell(): string | undefined {
9 if (process.platform === "win32") {
10 console.warn(`${getEnvPathFromUserShell.name} not implemented for Windows`);
11 return undefined;
12 }
13
14 if (!process.env.SHELL) {
15 return undefined;
16 }
17
18 try {
19 const command = `${process.env.SHELL} -l -c 'echo $PATH'`;
20
21 const stdout = execSync(command, {
22 encoding: "utf8",
23 });
24
25 return stdout.trim();
26 } catch (error) {
27 return process.env.PATH; // Fallback to current PATH
28 }
29}