2

There is an explanation on how to do that in a section in the alacritty's git-hub wiki, but I didn't get that. I experimented with it for example for solarized's light and dark version, but I failed.

Please show me how can I have multiple color-schemes at hand and how toggle/switch among them, preferably via key-strokes.

[I'm not sure this is the right place for this question, so let me know :)]

Edit: I fixed multiple schemes, according to the wiki. My mistake was I forgot to change the color keyword to a name that I then refer to. its like:

# XTerm's color-schemes
schemes:
    xterm_light: &light
           # Default colors
           primary:
             background: '#ffffff'
             foreground: '#000000'
           # Normal colors
           normal:
             black:   '#000000'
             red:     '#cd0000'
             green:   '#00cd00'
             yellow:  '#cdcd00'
             blue:    '#0000ee'
             magenta: '#cd00cd'
             cyan:    '#00adad'
             white:   '#c5c5c5'

           # Bright colors
           bright:
             black:   '#7f7f7f'
             red:     '#ff0000'
             green:   '#00ff00'
             yellow:  '#ffff00'
             blue:    '#5c5cff'
             magenta: '#ff00ff'
             cyan:    '#00fff             
             white:   '#ffffff'

    xterm_dark: &dark
           # Default colors
           primary:
             background: '#000000'
             foreground: '#ffffff'
           # Normal colors
           normal:
             black:   '#000000'
             red:     '#cd0000'
             green:   '#00cd00'
             yellow:  '#cdcd00'
             blue:    '#0050cc'
             magenta: '#cd00cd'
             cyan:    '#00adad'
             white:   '#e5e5e5'

           # Bright colors
           bright:
             black:   '#7f7f7f'
             red:     '#ff0000'
             green:   '#00ff00'
             yellow:  '#ffff00'
             blue:    '#5c5cff'
             magenta: '#ff00ff'
             cyan:    '#00ffff'
             white:   '#ffffff'

colors: *dark
# colors: *light

In this case I need to manually change the config in order to change the color-scheme. It's not the worst thing, but it would be nice to change it by keyboard shortcut.

1 Answer 1

2

[I'm not sure this is the right place for this question, so let me know :)]

Since this is my first answer here, I don't know if this is the right place for the question :-). But, I had the same problem a little while back and fixed it with the following python script:

#!/usr/bin/env python

import yaml
import os
import re


CONFIG_FILE_NAME = "alacritty.yml"
CONFIG_FILE_DIR = os.path.expanduser("~/.config/alacritty/")
CONFIG_FILE_PATH = os.path.join(CONFIG_FILE_DIR, CONFIG_FILE_NAME)

COLOR_SCHEME_LINE_SEARCH = "colors: \*(\S+)"
COLOR_SCHEME_LINE_TEMPLATE = "colors: *{}\n"

with open(CONFIG_FILE_PATH, "r") as config_file:
    config = yaml.safe_load(config_file)
    config_file.seek(0)
    lines = config_file.readlines()

colors_line_index = -1
for i, line in enumerate(lines):
    match = re.search(COLOR_SCHEME_LINE_SEARCH, line)
    if match is not None:
        current_color_scheme = match.group(1)
        colors_line_index = i

available_color_schemes = list(config["schemes"].keys())

color_scheme_index = available_color_schemes.index(current_color_scheme)
color_scheme_index = \
    (color_scheme_index + 1) % len(available_color_schemes)

lines[colors_line_index] = COLOR_SCHEME_LINE_TEMPLATE.format(
    available_color_schemes[color_scheme_index])

with open(CONFIG_FILE_PATH, "w") as config_file:
    for line in lines:
        config_file.write(line)

Depending on where your alacritty config file is, you might have to adjust the CONFIG_FILE_NAME and the CONFIG_FILE_DIR. For the script to work it is important that you name the anchors of the color schemes exactly the same as the color schemes themselfs, e.g.:

schemes:
  example_color_scheme: &example_color_schme
    primary:
        ...
    normal:
        ...
    bright:
        ...

Other than that the Python package pyyaml has to be installed on your system, the script has to be made executable by the user, and the script must be reachable from the user's PATH.

Additionally I put the following in my alacritty config file:

key_bindings:
  - { key: F, mods: Control, command: {program: "set_colorscheme.py"} }

This way, I can cycle through my color schems by pressing <CTRL-F>.

You can check it out the scipt in my dotfiles on github.

I hope that helps.

2
  • Thank you! I switched to st because of some bugs in alacritty 4.3 (i use debian), so I haven't tested your script yet. however, I accept this answer, because I assume this works for you. I hope this will be useful.
    – ali b
    Oct 14, 2020 at 12:45
  • Thanks for accepting my answer. It indeed works for me.
    – schuam
    Oct 19, 2020 at 17:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.