Skip to content

Commit

Permalink
fix: correctly identify powershell on windows (#1134)
Browse files Browse the repository at this point in the history
* fix: correctly identify powershell

* test: windows shell test

* test: windows shell test

* test: load config

---------

Co-authored-by: Cristian Dominguez <[email protected]>
  • Loading branch information
mdonnalley and cristiand391 authored Jul 9, 2024
1 parent 6488568 commit bcec7df
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
17 changes: 14 additions & 3 deletions test/config/config.shell.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
})
Expand Down

0 comments on commit bcec7df

Please sign in to comment.