diff --git a/src/config/config.ts b/src/config/config.ts index cf462431..f21b1198 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -663,6 +663,10 @@ export class Config implements IConfig { const SHELL = process.env.SHELL ?? osUserInfo().shell?.split(sep)?.pop() if (SHELL) { shellPath = SHELL.split('/') + } else if (this.windows && process.title.toLowerCase().includes('powershell')) { + shellPath = ['powershell'] + } else if (this.windows && process.title.toLowerCase().includes('command prompt')) { + shellPath = ['cmd.exe'] } else if (this.windows && COMSPEC) { shellPath = COMSPEC.split(/\\|\//) } else { diff --git a/test/config/config.shell.test.ts b/test/config/config.shell.test.ts index cb8ce96e..fcda9f02 100644 --- a/test/config/config.shell.test.ts +++ b/test/config/config.shell.test.ts @@ -4,11 +4,22 @@ import {sep} from 'node:path' import {Config} from '../../src' -const getShell = () => osUserInfo().shell?.split(sep)?.pop() || 'unknown' +const getShell = () => + osUserInfo().shell?.split(sep)?.pop() || (process.platform === 'win32' ? 'powershell' : 'unknown') describe('config shell', () => { - it('has a default shell', () => { - const config = new Config({root: '/tmp'}) + it('has a default shell', async () => { + const config = new Config({ + root: '/tmp', + pjson: { + name: 'test-cli', + version: '0.0.1', + oclif: { + bin: 'test-cli', + }, + }, + }) + await config.load() // @ts-expect-error because _shell is private expect(config._shell()).to.equal(getShell(), `SHELL: ${process.env.SHELL} COMSPEC: ${process.env.COMSPEC}`) })