mirror of
https://github.com/Eugeny/tabby.git
synced 2025-10-04 14:04:56 +00:00
auto-search powershell $PATH
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
import * as path from 'path'
|
||||
import * as fs from 'fs/promises'
|
||||
import hasbin from 'hasbin'
|
||||
import { promisify } from 'util'
|
||||
import { Injectable } from '@angular/core'
|
||||
import { HostAppService, Platform } from 'tabby-core'
|
||||
import { ElectronService } from 'tabby-electron'
|
||||
@@ -59,7 +62,7 @@ export class WindowsStockShellsProvider extends ShellProvider {
|
||||
{
|
||||
id: 'powershell',
|
||||
name: 'PowerShell',
|
||||
command: 'powershell.exe',
|
||||
command: await this.getPowerShellPath(),
|
||||
args: ['-nologo'],
|
||||
icon: require('../icons/powershell.svg'),
|
||||
env: {
|
||||
@@ -68,4 +71,23 @@ export class WindowsStockShellsProvider extends ShellProvider {
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
private async getPowerShellPath () {
|
||||
const ps = 'powershell.exe'
|
||||
|
||||
if (!await promisify(hasbin)(ps)) {
|
||||
for (const searchPath of [
|
||||
`${process.env.SystemRoot}\\System32\\WindowsPowerShell\\v1.0`,
|
||||
`${process.env.SystemRoot}\\System32`,
|
||||
process.env.SystemRoot ?? 'C:\\Windows',
|
||||
]) {
|
||||
const newPath = path.join(searchPath, ps)
|
||||
try {
|
||||
await fs.stat(newPath)
|
||||
return newPath
|
||||
} catch { }
|
||||
}
|
||||
}
|
||||
return ps
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user