import { readFileSync, appendFileSync } from "node:fs"; import { homedir } from "node:os"; import { join } from "node:path"; import { log } from "../log.js"; export function addToPath(): void { const shell = process.env.SHELL ?? "/bin/zsh"; let rcFile: string; if (shell.endsWith("/zsh")) { rcFile = join(homedir(), ".zshrc"); } else if (shell.endsWith("/bash")) { rcFile = join(homedir(), ".bashrc"); } else { rcFile = join(homedir(), ".profile"); } let contents = ""; try { contents = readFileSync(rcFile, "utf-8"); } catch { // File doesn't exist yet, that's fine } if (contents.includes(".local/bin")) { return; } appendFileSync( rcFile, '\n# Local AI coding tools\nexport PATH="$HOME/.local/bin:$PATH"\n', ); log(`Added ~/.local/bin to PATH in ${rcFile}`); }