dotfiles.nix/modules/home/programs/helix/extras.nix

48 lines
1.3 KiB
Nix
Raw Normal View History

2022-11-28 21:55:43 +00:00
{ config, lib, pkgs, ... }:
let
cfg = config.programs.helix;
inherit (cfg) extras;
tomlFormat = pkgs.formats.toml { };
inherit (lib) mkIf mkEnableOption mkOption types;
2023-08-23 00:50:29 +00:00
in {
2022-11-28 21:55:43 +00:00
options.programs.helix.extras = {
2023-08-23 00:50:29 +00:00
autoTheme.enable =
mkEnableOption "Automatically switch helix theme with night mode";
2022-11-28 21:55:43 +00:00
autoTheme.light = mkOption {
type = types.str;
description = "Light mode theme";
};
autoTheme.dark = mkOption {
type = types.str;
description = "Dark mode theme";
};
};
config = mkIf (cfg.enable && extras.autoTheme.enable) {
xdg.configFile = {
2023-08-23 00:50:29 +00:00
"helix/light.toml".source = tomlFormat.generate "helix-autotheme"
(cfg.settings // { theme = extras.autoTheme.light; });
"helix/dark.toml".source = tomlFormat.generate "helix-autotheme"
(cfg.settings // { theme = extras.autoTheme.dark; });
2022-11-28 21:55:43 +00:00
};
programs.fish.functions = {
hx = {
2022-11-28 22:01:54 +00:00
wraps = "hx";
2023-08-23 00:50:29 +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
'';
};
};
};
}