mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-22 18:24:21 +01:00
fix: make shell more robust (#3051)
This commit is contained in:
@@ -1290,20 +1290,46 @@ export namespace SessionPrompt {
|
|||||||
const shell = process.env["SHELL"] ?? "bash"
|
const shell = process.env["SHELL"] ?? "bash"
|
||||||
const shellName = path.basename(shell)
|
const shellName = path.basename(shell)
|
||||||
|
|
||||||
const scripts: Record<string, string> = {
|
const invocations: Record<string, { args: string[] }> = {
|
||||||
nu: input.command,
|
nu: {
|
||||||
fish: `eval "${input.command}"`,
|
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 =
|
const matchingInvocation = invocations[shellName] ?? invocations[""];
|
||||||
scripts[shellName] ??
|
const args = matchingInvocation?.args
|
||||||
`[[ -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 proc = spawn(shell, args, {
|
const proc = spawn(shell, args, {
|
||||||
cwd: Instance.directory,
|
cwd: Instance.directory,
|
||||||
|
|||||||
Reference in New Issue
Block a user