diff --git a/terminus-terminal/src/index.ts b/terminus-terminal/src/index.ts index 5f27c1fb..b085e648 100644 --- a/terminus-terminal/src/index.ts +++ b/terminus-terminal/src/index.ts @@ -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: [ diff --git a/terminus-terminal/src/shells/powershellCore.ts b/terminus-terminal/src/shells/powershellCore.ts new file mode 100644 index 00000000..25d86f73 --- /dev/null +++ b/terminus-terminal/src/shells/powershellCore.ts @@ -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 { + if (this.hostApp.platform !== Platform.Windows) { + return [] + } + + let pwshPath = await new Promise(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', + } + }] + } +} diff --git a/terminus-terminal/src/shells/windowsStock.ts b/terminus-terminal/src/shells/windowsStock.ts index ad0d15b7..041c680b 100644 --- a/terminus-terminal/src/shells/windowsStock.ts +++ b/terminus-terminal/src/shells/windowsStock.ts @@ -42,14 +42,6 @@ export class WindowsStockShellsProvider extends ShellProvider { TERM: 'cygwin', } }, - { - id: 'powershell-core', - name: 'PowerShell Core', - command: 'pwsh.exe', - env: { - TERM: 'cygwin', - } - }, ] } }