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

49 lines
1.3 KiB
Nix

{ config, lib, pkgs, ... }:
let
cfg = config.programs.helix;
inherit (cfg) extras;
tomlFormat = pkgs.formats.toml { };
inherit (lib) mkIf mkEnableOption mkOption types;
in
{
options.programs.helix.extras = {
autoTheme.enable = mkEnableOption "Automatically switch helix theme with night mode";
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 = {
"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; });
};
programs.fish.shellAbbrs = {
hxl = "${cfg.package} --config ${config.xdg.configHome}/helix/light.toml";
hxd = "${cfg.package} --config ${config.xdg.configHome}/helix/dark.toml";
};
programs.fish.functions = {
hx = {
description = "Helix invocation wrapper to automatically select the right theme";
body = ''
if is-dark-mode
hxd $argv
else
hxl $argv
end
'';
};
};
};
}