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

81 lines
2.1 KiB
Nix
Raw Normal View History

2022-07-26 04:22:16 +00:00
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.programs.kakoune.extras;
makeKakouneFace = face: name:
let
mkColor = name:
2023-08-23 00:50:29 +00:00
if hasPrefix "#" name then
"rgb:${substring 1 (-1) name}"
else if hasPrefix "!#" name then
"rgba:${substring 2 (-1) name}"
else
name;
value = if isList name then
concatStringsSep "," (map mkColor name)
else
mkColor name;
in "face global ${face} ${value}";
2022-07-26 04:22:16 +00:00
makeKakouneColors = faces:
concatStringsSep "\n"
2023-08-23 00:50:29 +00:00
([ "# Generated by home-manager" ] ++ mapAttrsToList makeKakouneFace faces);
2022-07-26 04:22:16 +00:00
2023-08-23 00:50:29 +00:00
writeKakouneConfig = file: config:
pkgs.writeText file (makeKakouneColors config);
2022-07-26 04:22:16 +00:00
kakoune-colors = {
light = writeKakouneConfig "light.kak" cfg.colors.light;
dark = writeKakouneConfig "dark.kak" cfg.colors.dark;
};
kak-background = pkgs.writeShellScriptBin "kak-background" ''
for session in $(kak -l); do
kak -c $session -e "colorscheme $1;q"
done
'';
kak-light = pkgs.writeShellScriptBin "kak-light" ''
${kak-background}/bin/kak-background light
'';
kak-dark = pkgs.writeShellScriptBin "kak-dark" ''
${kak-background}/bin/kak-background dark
'';
2023-08-23 00:50:29 +00:00
in {
2022-07-26 04:22:16 +00:00
options.programs.kakoune.extras = {
colors = {
enable = mkEnableOption "Custom kakoune color handling";
dark = mkOption {
type = with types; attrsOf (either str (listOf str));
description = "Kakoune dark colors";
};
light = mkOption {
type = with types; attrsOf (either str (listOf str));
description = "Kakoune light colors";
};
};
};
config = mkIf config.programs.kakoune.enable {
2023-08-23 00:50:29 +00:00
home.packages =
mkIf cfg.colors.enable [ kak-light kak-dark kak-background ];
2022-07-26 04:22:16 +00:00
xdg.configFile."kak/colors/light.kak".source = kakoune-colors.light;
xdg.configFile."kak/colors/dark.kak".source = kakoune-colors.dark;
programs.kakoune.extraConfig = ''
eval %sh{
if is-dark-mode; then
echo "colorscheme dark"
else
echo "colorscheme light"
fi
}
'';
};
}