Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions apps/server/src/terminal/Manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1946,6 +1946,32 @@ it.layer(
}),
);

it.effect("starts a $SHELL whose path contains a space", () =>
Effect.gen(function* () {
const { manager, ptyAdapter } = yield* createManager(5, {
env: { SHELL: "/Users/Jane Doe/.local/bin/fish" },
}).pipe(Effect.provide(layerWithHostPlatform("darwin")));

yield* manager.open(openInput());

expect(ptyAdapter.spawnInputs.map((input) => input.shell)).toEqual([
"/Users/Jane Doe/.local/bin/fish",
]);
}),
);

it.effect("starts a quoted $SHELL whose path contains a space and a dash", () =>
Effect.gen(function* () {
const { manager, ptyAdapter } = yield* createManager(5, {
env: { SHELL: '"/opt/my -shell/fish" -l' },
}).pipe(Effect.provide(layerWithHostPlatform("darwin")));

yield* manager.open(openInput());

expect(ptyAdapter.spawnInputs.map((input) => input.shell)).toEqual(["/opt/my -shell/fish"]);
}),
);

it.effect(
"writes completion syntax for the fallback shell instead of the configured fish shell",
() =>
Expand Down
8 changes: 5 additions & 3 deletions apps/server/src/terminal/Manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,9 +539,11 @@ function normalizeShellCommand(
return trimmed;
}

const firstToken = trimmed.split(/\s+/g)[0]?.trim();
if (!firstToken) return null;
return firstToken.replace(/^['"]|['"]$/g, "");
// A shell path can contain spaces, so only text from the first flag (`bash -l`) is dropped,
// and a quoted path is kept whole even when it contains " -".
const quoted = /^(['"])(.*?)\1(?:\s|$)/.exec(trimmed);
const command = quoted ? quoted[2] : trimmed.split(/\s+(?=-)/)[0]?.replace(/^['"]|['"]$/g, "");
Comment thread
MarcoDotIO marked this conversation as resolved.
Resolved
return command || null;
}

function basenameForPlatform(command: string, platform: NodeJS.Platform): string {
Expand Down
Loading