scan wsl distros directly in registry

This commit is contained in:
Eugene Pankov 2018-10-08 13:57:33 -07:00
parent 2ec3833977
commit 665a8e714e
2 changed files with 21 additions and 24 deletions

View File

@ -56,6 +56,7 @@ export interface IShell {
command: string command: string
args?: string[] args?: string[]
env?: any env?: any
fsBase?: string
} }
export abstract class ShellProvider { export abstract class ShellProvider {

View File

@ -1,5 +1,5 @@
import * as fs from 'mz/fs' import * as fs from 'mz/fs'
import { exec } from 'mz/child_process' import { Registry } from 'rage-edit'
import { Injectable } from '@angular/core' import { Injectable } from '@angular/core'
import { HostAppService, Platform } from 'terminus-core' import { HostAppService, Platform } from 'terminus-core'
@ -20,9 +20,19 @@ export class WSLShellProvider extends ShellProvider {
const bashPath = `${process.env.windir}\\system32\\bash.exe` const bashPath = `${process.env.windir}\\system32\\bash.exe`
const wslPath = `${process.env.windir}\\system32\\wsl.exe` const wslPath = `${process.env.windir}\\system32\\wsl.exe`
const wslConfigPath = `${process.env.windir}\\system32\\wslconfig.exe`
if (!await fs.exists(wslPath)) { let shells: IShell[] = [{
id: 'wsl',
name: 'WSL / Default distro',
command: wslPath,
env: {
TERM: 'xterm-color',
COLORTERM: 'truecolor',
}
}]
let lxss = await Registry.get('HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Lxss', true)
if (!lxss || !lxss.$values.defaultdistribution) {
if (await fs.exists(bashPath)) { if (await fs.exists(bashPath)) {
return [{ return [{
id: 'wsl', id: 'wsl',
@ -37,31 +47,17 @@ export class WSLShellProvider extends ShellProvider {
return [] return []
} }
} }
for (let child of Object.values(lxss)) {
let lines = (await exec(`${wslConfigPath} /l`, { encoding: 'ucs2' }))[0].toString().split('\n').splice(1) if (!child.$values) {
let shells: IShell[] = [{
id: 'wsl',
name: 'WSL / Default distro',
command: wslPath,
env: {
TERM: 'xterm-color',
COLORTERM: 'truecolor',
}
}]
for (let line of lines) {
line = line.trim()
if (!line) {
continue continue
} }
if (line.endsWith('(Default)')) { let name = child.$values.distributionname
line = line.substring(0, line.length - ' (Default)'.length)
}
shells.push({ shells.push({
id: `wsl-${line}`, id: `wsl-${name}`,
name: `WSL / ${line}`, name: `WSL / ${name}`,
command: wslPath, command: wslPath,
args: ['-d', line], args: ['-d', name],
fsBase: child.$values.basepath,
env: { env: {
TERM: 'xterm-color', TERM: 'xterm-color',
COLORTERM: 'truecolor', COLORTERM: 'truecolor',