Skip to content

Instantly share code, notes, and snippets.

@rafaelrinaldi
Created April 27, 2023 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafaelrinaldi/14771dce711fdf058f52cb0e49c93751 to your computer and use it in GitHub Desktop.
Save rafaelrinaldi/14771dce711fdf058f52cb0e49c93751 to your computer and use it in GitHub Desktop.
Easily switch between Alacritty themes

alacritty-theme

themes/

Create a themes/ folder under ~/.config/alacritty.

~/.config/alacritty
❯ ls -h
alacritty.yml theme.yml     themes

theme.yml

Create a theme.yml file under ~/.config/alacritty and import it in your own Alacritty config, at the very end of it:

# ~/.config/alacritty/alacritty.yml

# (...)

import:
  - ~/.config/alacritty/theme.yml

Themes are just plain Alacritty configuration files with color overrides and their file names are their keys. Here's Solarized Dark, for example:

# ~/.config/alacritty/themes/solarized-dark.yml
colors:
  primary:
    background: '0x002b36'
    foreground: '0x839496'

  normal:
    black:   '0x073642'
    red:     '0xdc322f'
    green:   '0x859900'
    yellow:  '0xb58900'
    blue:    '0x268bd2'
    magenta: '0xd33682'
    cyan:    '0x2aa198'
    white:   '0xeee8d5'

  bright:
    black:   '0x002b36'
    red:     '0xcb4b16'
    green:   '0x586e75'
    yellow:  '0x657b83'
    blue:    '0x839496'
    magenta: '0x6c71c4'
    cyan:    '0x93a1a1'
    white:   '0xfdf6e3'

Alacritty config reload

Enable live_config_reload on your Alacritty settings. This is so you don't have to manually reload/restart Alacritty for config changes to take effect.

alacritty-theme

Lastly add an alacritty-theme function to your zsh/bash profile:

function alacritty-theme() {
  local new_theme="${1:-dracula-pro}" # defaults to `dracula-pro` :heart:
  local config_path="$HOME/.config/alacritty"
  local themes_path=$config_path/themes
  local new_theme_file="$themes_path/$new_theme.yml"

  if [ ! -f $new_theme_file ]; then
    echo "Invalid Alacritty theme: $new_theme"
    return
  fi

  echo "import:\n  - $new_theme_file" > $config_path/theme.yml
}

GG

alacritty-theme.mov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment