Browse Source

fix: fish shell (#1950)

Aiden Cline 6 months ago
parent
commit
62fed8d2ce
1 changed files with 15 additions and 7 deletions
  1. 15 7
      packages/opencode/src/session/index.ts

+ 15 - 7
packages/opencode/src/session/index.ts

@@ -1056,14 +1056,22 @@ export namespace Session {
     }
     await updatePart(part)
     const app = App.info()
-    const script = `
-     [[ -f ~/.zshrc ]] && source ~/.zshrc >/dev/null 2>&1 || true
-     [[ -f ~/.bashrc ]] && source ~/.bashrc >/dev/null 2>&1 || true
-     eval "${input.command}"
-   `
     const shell = process.env["SHELL"] ?? "bash"
-    const supportsLoginFlag = !shell.includes("fish") && !shell.includes("nu")
-    const args = supportsLoginFlag ? ["-c", "-l", script] : ["-c", script]
+    const shellName = path.basename(shell)
+
+    const scripts: Record<string, string> = {
+      nu: input.command,
+      fish: `eval "${input.command}"`,
+    }
+
+    const script =
+      scripts[shellName] ??
+      `[[ -f ~/.zshrc ]] && source ~/.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 proc = spawn(shell, args, {
       cwd: app.path.cwd,