summaryrefslogtreecommitdiffhomepage
path: root/packages
diff options
context:
space:
mode:
authorHaris Gušić <[email protected]>2025-10-14 00:37:35 +0200
committerGitHub <[email protected]>2025-10-13 17:37:35 -0500
commitdbe9fd00b773d4623f1cd6c1b488e09602a7e925 (patch)
treef5a2322642d5cb47646acb99b0e2fd4da612183c /packages
parentcd13a8524e20bbd1609a20399e2db3c9aa8c7ba8 (diff)
downloadopencode-dbe9fd00b773d4623f1cd6c1b488e09602a7e925.tar.gz
opencode-dbe9fd00b773d4623f1cd6c1b488e09602a7e925.zip
fix: make shell more robust (#3051)
Diffstat (limited to 'packages')
-rw-r--r--packages/opencode/src/session/prompt.ts50
1 files changed, 38 insertions, 12 deletions
diff --git a/packages/opencode/src/session/prompt.ts b/packages/opencode/src/session/prompt.ts
index 0ccb208c6..1caa06744 100644
--- a/packages/opencode/src/session/prompt.ts
+++ b/packages/opencode/src/session/prompt.ts
@@ -1290,20 +1290,46 @@ export namespace SessionPrompt {
const shell = process.env["SHELL"] ?? "bash"
const shellName = path.basename(shell)
- const scripts: Record<string, string> = {
- nu: input.command,
- fish: `eval "${input.command}"`,
+ const invocations: Record<string, { args: string[] }> = {
+ nu: {
+ args: ["-c", input.command],
+ },
+ fish: {
+ args: ["-c", input.command],
+ },
+ zsh: {
+ args: [
+ "-c",
+ "-l",
+ `
+ [[ -f ~/.zshenv ]] && source ~/.zshenv >/dev/null 2>&1 || true
+ [[ -f "\${ZDOTDIR:-$HOME}/.zshrc" ]] && source "\${ZDOTDIR:-$HOME}/.zshrc" >/dev/null 2>&1 || true
+ ${input.command}
+ `
+ ],
+ },
+ bash: {
+ args: [
+ "-c",
+ "-l",
+ `
+ [[ -f ~/.bashrc ]] && source ~/.bashrc >/dev/null 2>&1 || true
+ ${input.command}
+ `,
+ ],
+ },
+ // Fallback: any shell that doesn't match those above
+ "": {
+ args: [
+ "-c",
+ "-l",
+ `${input.command}`,
+ ],
+ },
}
- const script =
- scripts[shellName] ??
- `[[ -f ~/.zshenv ]] && source ~/.zshenv >/dev/null 2>&1 || true
- [[ -f "\${ZDOTDIR:-$HOME}/.zshrc" ]] && source "\${ZDOTDIR:-$HOME}/.zshrc" >/dev/null 2>&1 || true
- [[ -f ~/.bashrc ]] && source ~/.bashrc >/dev/null 2>&1 || true
- eval "${input.command}"`
-
- const isFishOrNu = shellName === "fish" || shellName === "nu"
- const args = isFishOrNu ? ["-c", script] : ["-c", "-l", script]
+ const matchingInvocation = invocations[shellName] ?? invocations[""];
+ const args = matchingInvocation?.args
const proc = spawn(shell, args, {
cwd: Instance.directory,