From edb2cf2b7bae752b87fce7dfbe9dd23a45b8ac96 Mon Sep 17 00:00:00 2001 From: Cyril Taylor Date: Mon, 20 Jan 2020 14:56:52 +0800 Subject: [PATCH] add icon for wsl distributions(#2020) --- terminus-terminal/src/icons/alpine.svg | 1 + terminus-terminal/src/icons/debian.svg | 1 + terminus-terminal/src/icons/linux.svg | 122 +++++++++++++++++++++++++ terminus-terminal/src/icons/suse.svg | 47 ++++++++++ terminus-terminal/src/icons/ubuntu.svg | 7 ++ terminus-terminal/src/shells/wsl.ts | 53 ++++++++--- 6 files changed, 219 insertions(+), 12 deletions(-) create mode 100644 terminus-terminal/src/icons/alpine.svg create mode 100644 terminus-terminal/src/icons/debian.svg create mode 100644 terminus-terminal/src/icons/linux.svg create mode 100644 terminus-terminal/src/icons/suse.svg create mode 100644 terminus-terminal/src/icons/ubuntu.svg diff --git a/terminus-terminal/src/icons/alpine.svg b/terminus-terminal/src/icons/alpine.svg new file mode 100644 index 00000000..b43ef681 --- /dev/null +++ b/terminus-terminal/src/icons/alpine.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/terminus-terminal/src/icons/debian.svg b/terminus-terminal/src/icons/debian.svg new file mode 100644 index 00000000..c8e64b2b --- /dev/null +++ b/terminus-terminal/src/icons/debian.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/terminus-terminal/src/icons/linux.svg b/terminus-terminal/src/icons/linux.svg new file mode 100644 index 00000000..522042fd --- /dev/null +++ b/terminus-terminal/src/icons/linux.svg @@ -0,0 +1,122 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/terminus-terminal/src/icons/suse.svg b/terminus-terminal/src/icons/suse.svg new file mode 100644 index 00000000..d07b613c --- /dev/null +++ b/terminus-terminal/src/icons/suse.svg @@ -0,0 +1,47 @@ + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/terminus-terminal/src/icons/ubuntu.svg b/terminus-terminal/src/icons/ubuntu.svg new file mode 100644 index 00000000..850665f7 --- /dev/null +++ b/terminus-terminal/src/icons/ubuntu.svg @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/terminus-terminal/src/shells/wsl.ts b/terminus-terminal/src/shells/wsl.ts index 5709eee9..cfc8b860 100644 --- a/terminus-terminal/src/shells/wsl.ts +++ b/terminus-terminal/src/shells/wsl.ts @@ -14,6 +14,19 @@ try { var wnr = require('windows-native-registry') // eslint-disable-line @typescript-eslint/no-var-requires } catch { } +// WSL Distribution List +// https://docs.microsoft.com/en-us/windows/wsl/install-win10#install-your-linux-distribution-of-choice +var wslIconMap: { [key: string]: string } = { + 'Alpine': 'alpine.svg', + 'Debian': 'debian.svg', + 'kali-linux': 'linux.svg', + 'SLES-12': 'suse.svg', + 'openSUSE-Leap-15-1': 'suse.svg', + 'Ubuntu-18.04': 'ubuntu.svg', + 'Ubuntu': 'ubuntu.svg', + 'Linux': 'linux.svg', +} + /** @hidden */ @Injectable() export class WSLShellProvider extends ShellProvider { @@ -31,23 +44,35 @@ export class WSLShellProvider extends ShellProvider { const bashPath = `${process.env.windir}\\system32\\bash.exe` const wslPath = `${process.env.windir}\\system32\\wsl.exe` - const shells: Shell[] = [{ - id: 'wsl', - name: 'WSL / Default distro', - command: wslPath, - env: { - TERM: 'xterm-color', - COLORTERM: 'truecolor', - }, - }] - const lxssPath = 'Software\\Microsoft\\Windows\\CurrentVersion\\Lxss' const lxss = wnr.getRegistryKey(wnr.HK.CU, lxssPath) + const shells: Shell[] = [] + + if (null != lxss && null != lxss.DefaultDistribution) { + const defaultDistKey = wnr.getRegistryKey(wnr.HK.CU, lxssPath + '\\' + String(lxss.DefaultDistribution.value)) + if (defaultDistKey.DistributionName) { + const shell: Shell = { + id: 'wsl', + name: 'WSL / Default distro', + command: wslPath, + env: { + TERM: 'xterm-color', + COLORTERM: 'truecolor', + }, + } + if (wslIconMap.hasOwnProperty(defaultDistKey.DistributionName.value)) { + shell['icon'] = require(`../icons/${wslIconMap[defaultDistKey.DistributionName.value]}`) + } + shells.push(shell) + } + } + if (!lxss || !lxss.DefaultDistribution || !isWindowsBuild(WIN_BUILD_WSL_EXE_DISTRO_FLAG)) { if (await fs.exists(bashPath)) { return [{ id: 'wsl', name: 'WSL / Bash on Windows', + icon: require(`../icons/${wslIconMap['linux']}`), command: bashPath, env: { TERM: 'xterm-color', @@ -64,7 +89,7 @@ export class WSLShellProvider extends ShellProvider { continue } const name = childKey.DistributionName.value - shells.push({ + const shell: Shell = { id: `wsl-${slug(name)}`, name: `WSL / ${name}`, command: wslPath, @@ -74,7 +99,11 @@ export class WSLShellProvider extends ShellProvider { TERM: 'xterm-color', COLORTERM: 'truecolor', }, - }) + } + if (wslIconMap.hasOwnProperty(name)) { + shell['icon'] = require(`../icons/${wslIconMap[name]}`) + } + shells.push(shell) } return shells