| 1 | import { exec } from "child_process"; |
| 2 | import { promisify } from "util"; |
| 3 | |
| 4 | const execAsync = promisify(exec); |
| 5 | export async function getEnvPathFromUserShell(): Promise<string | undefined> { |
| 6 | if (process.platform === "win32") { |
| 7 | console.warn(`${getEnvPathFromUserShell.name} not implemented for Windows`); |
| 8 | return undefined; |
| 9 | } |
| 10 | |
| 11 | if (!process.env.SHELL) { |
| 12 | return undefined; |
| 13 | } |
| 14 | |
| 15 | try { |
| 16 | // Source common profile files |
| 17 | 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'`; |
| 18 | |
| 19 | const { stdout } = await execAsync(command, { |
| 20 | encoding: "utf8", |
| 21 | }); |
| 22 | |
| 23 | return stdout.trim(); |
| 24 | } catch (error) { |
| 25 | return process.env.PATH; // Fallback to current PATH |
| 26 | } |
| 27 | } |