dotfiles.nix/home/extras/helix/auto-theme.nix

53 lines
1.2 KiB
Nix
Raw Permalink Normal View History

2024-07-18 14:16:04 +00:00
{
config,
pkgs,
lib,
...
}:
2022-11-28 21:55:43 +00:00
let
cfg = config.programs.helix;
tomlFormat = pkgs.formats.toml { };
2024-07-18 14:16:04 +00:00
in
{
2023-10-26 02:37:42 +00:00
options.programs.helix = {
2023-11-03 23:19:07 +00:00
autoTheme = {
2024-07-18 14:16:04 +00:00
enable = lib.mkEnableOption "Automatically switch helix theme with night mode";
2022-11-28 21:55:43 +00:00
2023-11-03 23:19:07 +00:00
light = lib.mkOption {
type = lib.types.str;
description = "Light mode theme";
};
2022-11-28 21:55:43 +00:00
2023-11-03 23:19:07 +00:00
dark = lib.mkOption {
type = lib.types.str;
description = "Dark mode theme";
};
2022-11-28 21:55:43 +00:00
};
};
config = lib.mkIf (cfg.enable && cfg.autoTheme.enable) {
2022-11-28 21:55:43 +00:00
xdg.configFile = {
2024-07-18 14:16:04 +00:00
"helix/light.toml".source = tomlFormat.generate "helix-autotheme" (
cfg.settings // { theme = cfg.autoTheme.light; }
);
"helix/dark.toml".source = tomlFormat.generate "helix-autotheme" (
cfg.settings // { theme = cfg.autoTheme.dark; }
);
2022-11-28 21:55:43 +00:00
};
programs.fish.functions = {
hx = {
2022-11-28 22:01:54 +00:00
wraps = "hx";
2024-07-18 14:16:04 +00:00
description = "Helix invocation wrapper to automatically select the right theme";
2022-11-28 21:55:43 +00:00
body = ''
if is-dark-mode
2022-11-28 22:01:54 +00:00
command hx --config ${config.xdg.configHome}/helix/dark.toml $argv
2022-11-28 21:55:43 +00:00
else
2022-11-28 22:01:54 +00:00
command hx --config ${config.xdg.configHome}/helix/light.toml $argv
2022-11-28 21:55:43 +00:00
end
'';
};
};
};
}