Skip to content

Instantly share code, notes, and snippets.

@sheldonhull
Created April 17, 2020 23:33
Show Gist options
  • Save sheldonhull/300cdea8f076af99d0c3eab568ab7a94 to your computer and use it in GitHub Desktop.
Save sheldonhull/300cdea8f076af99d0c3eab568ab7a94 to your computer and use it in GitHub Desktop.
convert vscode themes to terminal and add them to your profile settings json
<#
Install-Module -Name MSTerminalSettings
.LINK https://powers-hell.com/2020/04/05/replicate-your-favorite-vscode-theme-in-windows-terminal/
$themes = ls $env:UserProfile .vscode\extensions\*theme* | Select FullName | Out-GridView -PassThru | % { Get-VSCodeTheme $_.FullName }
# $themes = Get-VSCodeTheme -themePath "$env:UserProfile\.vscode\extensions\monokai.theme-monokai-pro-vscode-1.1.15"
$export = $themes | % { Import-VSCodeThemeToTerminal -theme $_ }
#>
function Get-VSCodeTheme
{
[cmdletbinding()]
param (
# Themes are located at: ls $env:UserProfile .vscode\extensions\*theme* | Select FullName
[Parameter(mandatory)]
[System.IO.FileInfo]$themePath
)
try
{
$theme = (Get-Content "$themePath/package.json" -Raw | ConvertFrom-Json).contributes.themes
$res = foreach ($t in $theme)
{
$themeConfigFile = (Get-Content (Resolve-Path $themePath/$($t.path)) -raw | ConvertFrom-Json)
[pscustomobject]@{
name = $themeConfigFile.name
type = $themeConfigFile.type
ansiColors = [pscustomobject]@{
name = $themeConfigFile.name
background = $themeConfigFile.colors.'terminal.background'
foreground = $themeConfigFile.colors.'terminal.foreground'
Black = $themeConfigFile.colors.'terminal.ansiBlack'
Blue = $themeConfigFile.colors.'terminal.ansiBlue'
BrightBlack = $themeConfigFile.colors.'terminal.ansiBrightBlack'
BrightBlue = $themeConfigFile.colors.'terminal.ansiBrightBlue'
BrightCyan = $themeConfigFile.colors.'terminal.ansiBrightCyan'
BrightGreen = $themeConfigFile.colors.'terminal.ansiBrightGreen'
BrightPurple = $themeConfigFile.colors.'terminal.ansiBrightMagenta'
BrightRed = $themeConfigFile.colors.'terminal.ansiBrightRed'
BrightWhite = $themeConfigFile.colors.'terminal.ansiBrightWhite'
BrightYellow = $themeConfigFile.colors.'terminal.ansiBrightYellow'
Cyan = $themeConfigFile.colors.'terminal.ansiCyan'
Green = $themeConfigFile.colors.'terminal.ansiGreen'
Purple = $themeConfigFile.colors.'terminal.ansiMagenta'
Red = $themeConfigFile.colors.'terminal.ansiRed'
White = $themeConfigFile.colors.'terminal.ansiWhite'
Yellow = $themeConfigFile.colors.'terminal.ansiYellow'
selectionBackground = $themeConfigFile.colors.'terminal.selectionBackground'
}
}
}
return $res
}
catch
{
Write-Warning $_
}
}
function Import-VSCodeThemeToTerminal
{
[cmdletbinding()]
param (
[parameter(ValueFromPipeline, ValueFromPipelineByPropertyName, ValueFromRemainingArguments)]
[PSCustomObject]$theme
)
try
{
#region Set cmdlet parameters
$params = @{ }
if ( $null -ne $theme.ansiColors.name)
{
$params.name = $theme.ansiColors.name
}
if ( $null -ne $theme.ansiColors.background)
{
$params.background = $theme.ansiColors.background
}
if ( $null -ne $theme.ansiColors.foreground)
{
$params.foreground = $theme.ansiColors.foreground
}
if ( $null -ne $theme.ansiColors.Black)
{
$params.Black = $theme.ansiColors.Black
}
if ( $null -ne $theme.ansiColors.Blue)
{
$params.Blue = $theme.ansiColors.Blue
}
if ( $null -ne $theme.ansiColors.BrightBlack)
{
$params.BrightBlack = $theme.ansiColors.BrightBlack
}
if ( $null -ne $theme.ansiColors.BrightBlue)
{
$params.BrightBlue = $theme.ansiColors.BrightBlue
}
if ( $null -ne $theme.ansiColors.BrightCyan)
{
$params.BrightCyan = $theme.ansiColors.BrightCyan
}
if ( $null -ne $theme.ansiColors.BrightGreen)
{
$params.BrightGreen = $theme.ansiColors.BrightGreen
}
if ( $null -ne $theme.ansiColors.Brightpurple)
{
$params.Brightpurple = $theme.ansiColors.Brightpurple
}
if ( $null -ne $theme.ansiColors.BrightRed)
{
$params.BrightRed = $theme.ansiColors.BrightRed
}
if ( $null -ne $theme.ansiColors.BrightWhite)
{
$params.BrightWhite = $theme.ansiColors.BrightWhite
}
if ( $null -ne $theme.ansiColors.BrightYellow)
{
$params.BrightYellow = $theme.ansiColors.BrightYellow
}
if ( $null -ne $theme.ansiColors.Cyan)
{
$params.Cyan = $theme.ansiColors.Cyan
}
if ( $null -ne $theme.ansiColors.Green)
{
$params.Green = $theme.ansiColors.Green
}
if ( $null -ne $theme.ansiColors.purple)
{
$params.purple = $theme.ansiColors.purple
}
if ( $null -ne $theme.ansiColors.Red)
{
$params.Red = $theme.ansiColors.Red
}
if ( $null -ne $theme.ansiColors.White)
{
$params.White = $theme.ansiColors.White
}
if ( $null -ne $theme.ansiColors.Yellow)
{
$params.Yellow = $theme.ansiColors.Yellow
}
#endregion
New-MSTerminalColorScheme @params
}
catch
{
Write-Warning $_
}
}
Export-ModuleMember -Function 'Get-VSCodeTheme', 'Import-VSCodeThemeToTerminal' -ErrorAction SilentlyContinue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment