Script for easily configuring, using, switching and comparing local offline coding models
1import { readFileSync, appendFileSync } from "node:fs";
2import { homedir } from "node:os";
3import { join } from "node:path";
4import { log } from "../log.js";
5
6export function addToPath(): void {
7 const shell = process.env.SHELL ?? "/bin/zsh";
8 let rcFile: string;
9
10 if (shell.endsWith("/zsh")) {
11 rcFile = join(homedir(), ".zshrc");
12 } else if (shell.endsWith("/bash")) {
13 rcFile = join(homedir(), ".bashrc");
14 } else {
15 rcFile = join(homedir(), ".profile");
16 }
17
18 let contents = "";
19 try {
20 contents = readFileSync(rcFile, "utf-8");
21 } catch {
22 // File doesn't exist yet, that's fine
23 }
24
25 if (contents.includes(".local/bin")) {
26 return;
27 }
28
29 appendFileSync(
30 rcFile,
31 '\n# Local AI coding tools\nexport PATH="$HOME/.local/bin:$PATH"\n',
32 );
33 log(`Added ~/.local/bin to PATH in ${rcFile}`);
34}