Gogh-Co / Gogh

Gogh is a collection of color schemes for various terminal emulators, including Gnome Terminal, Pantheon Terminal, Tilix, and XFCE4 Terminal also compatible with iTerm on macOS.
https://gogh-co.github.io/Gogh/
MIT License
9.22k stars 586 forks source link

[Feature request] Make it work on Windows Terminal /WSL2 #413

Open JulianGR opened 9 months ago

JulianGR commented 9 months ago

Hello,

I love Gogh and use it on my Kali VM. Lately, I've became a fan of WSL2 and Gogh doesn't seem to be working on WSL. I'm aware of https://github.com/Gogh-Co/Gogh/issues/183#issuecomment-501944788 and that there is no way that WSL changes the colors of Windows (maybe now there is, since a couple of years have passed?), but what about making Gogh work in Windows Terminal?

I'm not talking abount running Gogh inside WSL and it changing the Windows Terminal configuration, but rather running Gogh directly on Windows Terminal. I'm also aware that other tool exists, such as colortool, but I quite like Gogh

zoltan-kecskemethy-epam commented 7 months ago

I've a semi-automated migration process to convert a scheme from this repo and added it into Windows terminal. Not sure, but we might be able to turn it a script.

Let me describe what I did.

Windows terminal has its full configuration including color schemes defined in json format. Usually located at C:\Users\<username>\AppData\Local\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json There are many things in the config but there is a "schemes" section looks like:

    "schemes": 
    [
        {
            "background": "#1A1B26",
            "black": "#414868",
            "blue": "#7AA2F7",
            "brightBlack": "#414868",
            "brightBlue": "#7AA2F7",
            "brightCyan": "#7DCFFF",
            "brightGreen": "#9ECE6A",
            "brightPurple": "#7DCFFF",
            "brightRed": "#F7768E",
            "brightWhite": "#C0CAF5",
            "brightYellow": "#E0AF68",
            "cursorColor": "#FFFFFF",
            "cyan": "#7DCFFF",
            "foreground": "#C0CAF5",
            "green": "#9ECE6A",
            "name": "TokyoNight",
            "purple": "#7DCFFF",
            "red": "#F7768E",
            "selectionBackground": "#FFFFFF",
            "white": "#A9B1D6",
            "yellow": "#E0AF68"
        },
      <we-want-to-add-new-scheme-here>
    ],

I've used alacritty's json_str structure from here: https://github.com/Gogh-Co/Gogh/blob/master/apply-colors.sh#L472C1-L531C2

so created a windows terminal compatible json structure ...

win_term_json_str="\
{\
    \"schemes\": [\
        {\
            \"black\": \"$COLOR_01\",\
            \"red\": \"$COLOR_02\",\
            \"green\": \"$COLOR_03\",\
            \"yellow\":\"$COLOR_04\",\
            \"blue\":\"$COLOR_05\",\
            \"magenta\": \"$COLOR_06\",\
            \"cyan\":\"$COLOR_07\",\
            \"white\": \"$COLOR_08\",\
            \"brightblack\":\"$COLOR_09\",\
            \"brightred\":\"$COLOR_10\",\
            \"brightgreen\":\"$COLOR_11\",\
            \"brightyellow\": \"$COLOR_12\",\
            \"brightblue\": \"$COLOR_13\",\
            \"brightmagenta\":\"$COLOR_14\",\
            \"brightcyan\": \"$COLOR_15\",\
            \"brightwhite\":\"$COLOR_16\",\
            \"background\": \"$BACKGROUND_COLOR\",\
            \"foreground\": \"$FOREGROUND_COLOR\",\
            \"cursorColor\": \"$CURSOR_COLOR\",\
            \"selectionBackground\": \"$COLOR_16\",\
            \"name\": \"$PROFILE_NAME\"\
        }\
    ]\
}"

I was not sure which color to use for "selectionBackground" - as this looks to be missing - so I've just repeated COLOR_16 there.

As a final step we would need to merge above json into the main config...

Main config path in WSL could be mounted as /mnt/c/Users/$USER/AppData/Local/Packages/Microsoft.WindowsTerminal_8wekyb3d8bbwe/LocalState/settings.json

We can use jq tool for the merge.

So the overall process using zenburn scheme

cd install
source zenburn.sh
export win_term_json_str="\
{\
    \"schemes\": [\
        {\
            \"black\": \"$COLOR_01\",\
            \"red\": \"$COLOR_02\",\
            \"green\": \"$COLOR_03\",\
            \"yellow\":\"$COLOR_04\",\
            \"blue\":\"$COLOR_05\",\
            \"magenta\": \"$COLOR_06\",\
            \"cyan\":\"$COLOR_07\",\
            \"white\": \"$COLOR_08\",\
            \"brightblack\":\"$COLOR_09\",\
            \"brightred\":\"$COLOR_10\",\
            \"brightgreen\":\"$COLOR_11\",\
            \"brightyellow\": \"$COLOR_12\",\
            \"brightblue\": \"$COLOR_13\",\
            \"brightmagenta\":\"$COLOR_14\",\
            \"brightcyan\": \"$COLOR_15\",\
            \"brightwhite\":\"$COLOR_16\",\
            \"background\": \"$BACKGROUND_COLOR\",\
            \"foreground\": \"$FOREGROUND_COLOR\",\
            \"cursorColor\": \"$CURSOR_COLOR\",\
            \"selectionBackground\": \"$COLOR_16\",\
            \"name\": \"$PROFILE_NAME\"\
        }\
    ]\
}"
echo $win_term_json_str | jq . > /tmp/win-term-scheme.json
cp /mnt/c/Users/$USER/AppData/Local/Packages/Microsoft.WindowsTerminal_8wekyb3d8bbwe/LocalState/settings.json /tmp
jq -s '.[0] * .[1]' /tmp/win-term-scheme.json /tmp/settings.json > /tmp/new-settings.json

This is not foolproof, so make a backup of your config before overwriting it. Also this is the reason why I've made changes in files in /tmp ...

zoltan-kecskemethy-epam commented 7 months ago

Also be aware of https://github.com/mbadolato/iTerm2-Color-Schemes/tree/master/windowsterminal