| 1 | import { execSync } from "child_process"; |
| 2 | import { homedir } from "os"; |
| 3 | |
| 4 | export function getEnvPathFromUserShell(): string | undefined { |
| 5 | if (process.platform === "win32") { |
| 6 | console.warn(`${getEnvPathFromUserShell.name} not implemented for Windows`); |
| 7 | return undefined; |
| 8 | } |
| 9 | |
| 10 | if (!process.env.SHELL) { |
| 11 | return undefined; |
| 12 | } |
| 13 | |
| 14 | try { |
| 15 | // Source common profile files |
| 16 | const command = `${process.env.SHELL} -l -c 'for f in ~/.zprofile ~/.zshrc ~/.bash_profile ~/.bashrc; do [ -f "$f" ] && source "$f" 2>/dev/null; done; echo $PATH'`; |
| 17 | |
| 18 | const stdout = execSync(command, { |
| 19 | encoding: "utf8", |
| 20 | }); |
| 21 | |
| 22 | return stdout.trim(); |
| 23 | } catch (error) { |
| 24 | return process.env.PATH; // Fallback to current PATH |
| 25 | } |
| 26 | } |