Skip to content

Commit 9e62ba3

Browse files
committed
fix: add || true to bashrc snippet to prevent command chain failure
When ~/.mux/bashrc doesn't exist, [ -f ... ] returns non-zero. In SSH runtime, commands are joined with &&, so a non-zero return breaks the entire command chain. The pattern '[ -f file ] && . file || true' ensures: - If file exists: source it normally - If file doesn't exist: || true returns 0, chain continues
1 parent a7e2919 commit 9e62ba3

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/common/constants/paths.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ describe("getMuxBashrcSourceSnippet", () => {
2222
expect(snippet).toContain("$HOME/");
2323
});
2424

25-
it("should silently skip if file doesn't exist", () => {
25+
it("should silently skip if file doesn't exist and return success", () => {
2626
const snippet = getMuxBashrcSourceSnippet();
2727

28-
// Should use && to only source if test succeeds (file exists)
29-
// This pattern: [ -f file ] && . file
30-
// - If file doesn't exist, [ -f file ] returns 1, && short-circuits, no error
31-
// - If file exists, [ -f file ] returns 0, && continues to source file
28+
// Should use the pattern: [ -f file ] && . file || true
29+
// - If file doesn't exist, [ -f file ] returns 1, && short-circuits, || true returns 0
30+
// - If file exists, [ -f file ] returns 0, && sources file, || is skipped
31+
// The || true is critical for SSH runtime where commands are joined with &&
3232
expect(snippet).toContain("] && .");
33+
expect(snippet).toContain("|| true");
3334
});
3435
});

src/common/constants/paths.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ export const MUX_BASHRC_FILENAME = "bashrc";
137137
*/
138138
export function getMuxBashrcSourceSnippet(): string {
139139
// Use $HOME/.mux/bashrc to work on both local and SSH runtimes
140-
// The -f test and source are combined to silently skip if file doesn't exist
141-
return `[ -f "$HOME/.mux/bashrc" ] && . "$HOME/.mux/bashrc"`;
140+
// The pattern `[ -f file ] && . file || true` ensures:
141+
// 1. If file exists: source it, return its exit status (typically 0)
142+
// 2. If file doesn't exist: [ -f ] returns 1, && short-circuits, || true returns 0
143+
// This is critical for SSH runtime where commands are joined with &&
144+
return `[ -f "$HOME/.mux/bashrc" ] && . "$HOME/.mux/bashrc" || true`;
142145
}

0 commit comments

Comments
 (0)