From 5bd14cffe98d057c062429bb130769e95ca65ee3 Mon Sep 17 00:00:00 2001 From: Romain Paquet Date: Tue, 27 Jan 2026 14:36:11 +0100 Subject: [PATCH] alacritty: auto switch dark/light theme --- home-manager/desktop/terminal.nix | 3 +- home/.config/alacritty/alacritty.toml | 4 +-- .../alacritty/themes/default_light.toml | 33 +++++++++++++++++++ home/bin/switch-helix-theme.sh | 18 ++++++++-- 4 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 home/.config/alacritty/themes/default_light.toml diff --git a/home-manager/desktop/terminal.nix b/home-manager/desktop/terminal.nix index 46ce790..5f35837 100644 --- a/home-manager/desktop/terminal.nix +++ b/home-manager/desktop/terminal.nix @@ -15,8 +15,7 @@ ]; programs.alacritty.enable = true; - xdg.configFile."alacritty/alacritty.toml".source = - "${config.dotfiles.path}/.config/alacritty/alacritty.toml"; + xdg.configFile."alacritty".source = "${config.dotfiles.path}/.config/alacritty"; xdg.configFile."ghostty/config".source = "${config.dotfiles.path}/.config/ghostty/config"; } diff --git a/home/.config/alacritty/alacritty.toml b/home/.config/alacritty/alacritty.toml index 62b95bd..cc3c2f0 100644 --- a/home/.config/alacritty/alacritty.toml +++ b/home/.config/alacritty/alacritty.toml @@ -1,6 +1,6 @@ [general] -live_config_reload = false -import = ["~/.config/alacritty/themes/kanagawa_wave.toml"] +live_config_reload = true +import = ["~/.config/alacritty/themes/default_light.toml"] [font] size = 14 diff --git a/home/.config/alacritty/themes/default_light.toml b/home/.config/alacritty/themes/default_light.toml new file mode 100644 index 0000000..50b2dc0 --- /dev/null +++ b/home/.config/alacritty/themes/default_light.toml @@ -0,0 +1,33 @@ +# Colors (Builtin Light) + +[colors.bright] +black = '#555555' +blue = '#5555ff' +cyan = '#22cccc' +green = '#2fd92f' +magenta = '#ff55ff' +red = '#ff5555' +white = '#ffffff' +yellow = '#bfbf15' + +[colors.cursor] +cursor = '#000000' +text = '#ffffff' + +[colors.normal] +black = '#000000' +blue = '#0000bb' +cyan = '#00bbbb' +green = '#00bb00' +magenta = '#bb00bb' +red = '#bb0000' +white = '#bbbbbb' +yellow = '#bbbb00' + +[colors.primary] +background = '#ffffff' +foreground = '#000000' + +[colors.selection] +background = '#b5d5ff' +text = '#000000' diff --git a/home/bin/switch-helix-theme.sh b/home/bin/switch-helix-theme.sh index f11f803..3d21409 100755 --- a/home/bin/switch-helix-theme.sh +++ b/home/bin/switch-helix-theme.sh @@ -6,10 +6,24 @@ HELIX_CONFIG_PATH=$(readlink -f "${HOME}/.config/helix/config.toml") HELIX_THEME_LIGHT="zed_onelight" HELIX_THEME_DARK="kanagawa" +ALACRITTY_CONFIG_PATH=$(readlink -f "${HOME}/.config/alacritty/alacritty.toml") +ALACRITTY_THEME_LIGHT="default_light" +ALACRITTY_THEME_DARK="kanagawa_wave" + +set_helix_theme() { + sed -i "s/^theme .*/theme = \"$1\"/" "$HELIX_CONFIG_PATH" +} + +set_alacritty_theme() { + sed -i "s/^import .*/import = \[\"\~\/\.config\/alacritty\/themes\/$1\.toml\"\]/" "$ALACRITTY_CONFIG_PATH" +} + if [[ "$2" == "prefer-dark" ]]; then - sed -i "s/^theme .*/theme = \"$HELIX_THEME_DARK\"/" "$HELIX_CONFIG_PATH" + set_helix_theme "$HELIX_THEME_DARK" + sey_alacritty_theme "$HELIX_THEME_DARK" else - sed -i "s/^theme .*/theme = \"$HELIX_THEME_LIGHT\"/" "$HELIX_CONFIG_PATH" + set_helix_theme "$HELIX_THEME_LIGHT" + set_alacritty_theme "$HELIX_THEME_LIGHT" fi pkill -USR1 hx || true