autodetect powershell core path (fixes #382)

This commit is contained in:
Eugene Pankov 2018-09-11 13:52:33 -07:00
parent d574f634c9
commit bf5e460bca
3 changed files with 50 additions and 8 deletions

View File

@ -35,6 +35,7 @@ import { GitBashShellProvider } from './shells/gitBash'
import { LinuxDefaultShellProvider } from './shells/linuxDefault'
import { MacOSDefaultShellProvider } from './shells/macDefault'
import { POSIXShellsProvider } from './shells/posix'
import { PowerShellCoreShellProvider } from './shells/powershellCore'
import { WindowsStockShellsProvider } from './shells/windowsStock'
import { WSLShellProvider } from './shells/wsl'
@ -73,6 +74,7 @@ import { hterm } from './hterm'
{ provide: ShellProvider, useClass: Cygwin64ShellProvider, multi: true },
{ provide: ShellProvider, useClass: GitBashShellProvider, multi: true },
{ provide: ShellProvider, useClass: POSIXShellsProvider, multi: true },
{ provide: ShellProvider, useClass: PowerShellCoreShellProvider, multi: true },
{ provide: ShellProvider, useClass: WSLShellProvider, multi: true },
],
entryComponents: [

View File

@ -0,0 +1,48 @@
import * as path from 'path'
import { Injectable } from '@angular/core'
import { HostAppService, Platform } from 'terminus-core'
import { ShellProvider, IShell } from '../api'
let Registry = null
try {
Registry = require('winreg')
} catch (_) { } // tslint:disable-line no-empty
@Injectable()
export class PowerShellCoreShellProvider extends ShellProvider {
constructor (
private hostApp: HostAppService,
) {
super()
}
async provide (): Promise<IShell[]> {
if (this.hostApp.platform !== Platform.Windows) {
return []
}
let pwshPath = await new Promise<string>(resolve => {
let reg = new Registry({ hive: Registry.HKLM, key: '\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\pwsh.exe', arch: 'x64' })
reg.get('', (err, item) => {
if (err || !item) {
return resolve(null)
}
resolve(item.value)
})
})
if (!pwshPath) {
return []
}
return [{
id: 'powershell-core',
name: 'PowerShell Core',
command: pwshPath,
env: {
TERM: 'cygwin',
}
}]
}
}

View File

@ -42,14 +42,6 @@ export class WindowsStockShellsProvider extends ShellProvider {
TERM: 'cygwin',
}
},
{
id: 'powershell-core',
name: 'PowerShell Core',
command: 'pwsh.exe',
env: {
TERM: 'cygwin',
}
},
]
}
}