Skip to content

Instantly share code, notes, and snippets.

@vbfox
Created April 21, 2017 12:39
Show Gist options
  • Save vbfox/7dbdc751b7fda4600c0a8c7a769edac1 to your computer and use it in GitHub Desktop.
Save vbfox/7dbdc751b7fda4600c0a8c7a769edac1 to your computer and use it in GitHub Desktop.
Configure cmd.exe to use the same colors as the current theme configured in ConEmu
#r "System.Xml.Linq"
open System
open System.Text.RegularExpressions
open System.Xml.Linq
open System.Xml.XPath
open Microsoft.Win32
let convert () =
let doc = XDocument.Load(Environment.ExpandEnvironmentVariables(@"%APPDATA%\ConEmu.xml"))
let values = doc.XPathSelectElements("/key[@name='Software']/key[@name='ConEmu']/key[@name='.Vanilla']/value")
let colors =
values
|> Seq.map(fun xvalue -> xvalue.Attribute(XName.Get("name")), xvalue.Attribute(XName.Get("data")))
|> Seq.filter(fun (name, value) -> name <> null && value <> null)
|> Seq.map(fun (name, value) -> name.Value, value.Value)
|> Seq.filter(fun (name, _) -> name.StartsWith("ColorTable"))
|> Seq.map(fun (name, value) -> name, Convert.ToInt32(value, 16))
|> Seq.filter(fun (name, _) ->
let index = int (Regex("ColorTable(\d+)").Match(name).Groups.[1].Value)
index < 16
)
|> List.ofSeq
use key = Registry.CurrentUser.OpenSubKey("Console", true)
for name, value in colors do
key.SetValue(name, value)
convert()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment