Skip to content

Commit 2fa5691

Browse files
t3dotggclaude
andcommitted
fix(shared): PATH command survives a final comment and skips macOS bash
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 14f0c8b commit 2fa5691

4 files changed

Lines changed: 21 additions & 12 deletions

File tree

‎apps/desktop/src/app/DesktopCliCommand.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ it.layer(NodeServices.layer)("DesktopCliCommand", (it) => {
134134
yield* command.installOnFirstLaunch;
135135
const installed = yield* command.state;
136136
expect(installed.installedPath).toBe(link);
137-
expect(installed.pathCommand).toBe(`echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc`);
137+
expect(installed.pathCommand).toBe(
138+
`printf '\\n%s\\n' 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc`,
139+
);
138140

139141
yield* command.uninstall;
140142
yield* command.installOnFirstLaunch;

‎apps/server/src/cli/install.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ it.layer(NodeServices.layer)("t3 install", (it) => {
5656
const installed = yield* provide(installCli());
5757
assert.equal(yield* fs.readLink(link), executable);
5858
assert.isFalse(installed.onPath);
59-
assert.equal(installed.pathCommand, `echo 'export PATH="$HOME/bin:$PATH"' >> ~/.zshrc`);
59+
assert.equal(
60+
installed.pathCommand,
61+
`printf '\\n%s\\n' 'export PATH="$HOME/bin:$PATH"' >> ~/.zshrc`,
62+
);
6063

6164
// A link written through a symlinked T3 home is still ours.
6265
const alias = path.join(root, "alias");

‎packages/shared/src/shell.test.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,19 +1052,20 @@ describe("pathSetupCommand", () => {
10521052
pathSetupCommand({ directory, home: "/Users/theo", shell, platform });
10531053

10541054
it("writes to the startup file of the user's shell", () => {
1055-
expect(command("/Users/theo/.local/bin", "/bin/bash", "darwin")).toBe(
1056-
`echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bash_profile`,
1055+
expect(command("/home/theo/.local/bin", "/bin/bash", "linux")).toBe(
1056+
`printf '\\n%s\\n' 'export PATH="/home/theo/.local/bin:$PATH"' >> ~/.bashrc`,
10571057
);
10581058
expect(command("/Users/theo/.local/bin", "/usr/bin/fish", "linux")).toBe(
10591059
"fish_add_path $HOME/.local/bin",
10601060
);
10611061
expect(command("/opt/t3/bin", "/bin/zsh", "linux")).toBe(
1062-
`echo 'export PATH="/opt/t3/bin:$PATH"' >> ~/.zshrc`,
1062+
`printf '\\n%s\\n' 'export PATH="/opt/t3/bin:$PATH"' >> ~/.zshrc`,
10631063
);
10641064
});
10651065

10661066
it("prints nothing for Windows, other shells, or a path a pasted command would mangle", () => {
10671067
expect(command("/Users/theo/.local/bin", "/bin/tcsh", "darwin")).toBeUndefined();
1068+
expect(command("/Users/theo/.local/bin", "/bin/bash", "darwin")).toBeUndefined();
10681069
expect(command("C:\\Users\\theo\\.local\\bin", "pwsh", "win32")).toBeUndefined();
10691070
expect(command("/Users/theo/it's here", "/bin/zsh", "darwin")).toBeUndefined();
10701071
expect(command("/opt/a$PWD/bin", "/bin/zsh", "linux")).toBeUndefined();

‎packages/shared/src/shell.ts‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ export const resolveWindowsEnvironment = Effect.fn("shell.resolveWindowsEnvironm
969969
/**
970970
* A command to paste that puts `directory` on PATH for new zsh, bash, or fish terminals. Undefined
971971
* on Windows (a pasted command would flatten the registry PATH's `%VAR%` entries), for other
972-
* shells, or for unsafe paths.
972+
* shells, macOS bash, or unsafe paths.
973973
*/
974974
export function pathSetupCommand(input: {
975975
readonly directory: string;
@@ -984,10 +984,13 @@ export function pathSetupCommand(input: {
984984
const directory = underHome ? `$HOME${rest}` : rest;
985985
const shell = input.shell?.split("/").pop();
986986
if (shell === "fish") return `fish_add_path ${directory}`;
987-
const line = `export PATH="${directory}:$PATH"`;
988-
if (shell === "zsh") return `echo '${line}' >> ~/.zshrc`;
989-
if (shell === "bash") {
990-
return `echo '${line}' >> ${input.platform === "darwin" ? "~/.bash_profile" : "~/.bashrc"}`;
991-
}
992-
return undefined;
987+
// macOS bash reads only the first of .bash_profile, .bash_login, and .profile; no file is safe.
988+
const rc =
989+
shell === "zsh"
990+
? "~/.zshrc"
991+
: shell === "bash" && input.platform !== "darwin"
992+
? "~/.bashrc"
993+
: undefined;
994+
// The leading newline keeps the line out of a final comment with no newline after it.
995+
return rc && `printf '\\n%s\\n' 'export PATH="${directory}:$PATH"' >> ${rc}`;
993996
}

0 commit comments

Comments
 (0)