@@ -9,6 +9,7 @@ import { app } from "electron"
99import treeKill from "tree-kill"
1010
1111import { WSL_ENABLED_KEY } from "./constants"
12+ import { getUserShell , loadShellEnv , mergeShellEnv } from "./shell-env"
1213import { store } from "./store"
1314
1415const CLI_INSTALL_DIR = ".opencode/bin"
@@ -135,16 +136,18 @@ export function spawnCommand(args: string, extraEnv: Record<string, string>) {
135136 const base = Object . fromEntries (
136137 Object . entries ( process . env ) . filter ( ( entry ) : entry is [ string , string ] => typeof entry [ 1 ] === "string" ) ,
137138 )
138- const envs = {
139+ const env = {
139140 ...base ,
140141 OPENCODE_EXPERIMENTAL_ICON_DISCOVERY : "true" ,
141142 OPENCODE_EXPERIMENTAL_FILEWATCHER : "true" ,
142143 OPENCODE_CLIENT : "desktop" ,
143144 XDG_STATE_HOME : app . getPath ( "userData" ) ,
144145 ...extraEnv ,
145146 }
147+ const shell = process . platform === "win32" ? null : getUserShell ( )
148+ const envs = shell ? mergeShellEnv ( loadShellEnv ( shell ) , env ) : env
146149
147- const { cmd, cmdArgs } = buildCommand ( args , envs )
150+ const { cmd, cmdArgs } = buildCommand ( args , envs , shell )
148151 console . log ( `[cli] Executing: ${ cmd } ${ cmdArgs . join ( " " ) } ` )
149152 const child = spawn ( cmd , cmdArgs , {
150153 env : envs ,
@@ -210,7 +213,7 @@ function handleSqliteProgress(events: EventEmitter, line: string) {
210213 return false
211214}
212215
213- function buildCommand ( args : string , env : Record < string , string > ) {
216+ function buildCommand ( args : string , env : Record < string , string > , shell : string | null ) {
214217 if ( process . platform === "win32" && isWslEnabled ( ) ) {
215218 console . log ( `[cli] Using WSL mode` )
216219 const version = app . getVersion ( )
@@ -233,10 +236,10 @@ function buildCommand(args: string, env: Record<string, string>) {
233236 }
234237
235238 const sidecar = getSidecarPath ( )
236- const shell = process . env . SHELL || "/bin/sh"
237- const line = shell . endsWith ( "/nu" ) ? `^\"${ sidecar } \" ${ args } ` : `\"${ sidecar } \" ${ args } `
238- console . log ( `[cli] Unix mode, shell: ${ shell } , command: ${ line } ` )
239- return { cmd : shell , cmdArgs : [ "-l" , "-c" , line ] }
239+ const user = shell || getUserShell ( )
240+ const line = user . endsWith ( "/nu" ) ? `^\"${ sidecar } \" ${ args } ` : `\"${ sidecar } \" ${ args } `
241+ console . log ( `[cli] Unix mode, shell: ${ user } , command: ${ line } ` )
242+ return { cmd : user , cmdArgs : [ "-l" , "-c" , line ] }
240243}
241244
242245function envPrefix ( env : Record < string , string > ) {
0 commit comments