85 lines
2.1 KiB
Nix
85 lines
2.1 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.programs.kakoune.extras;
|
|
|
|
makeKakouneFace = face: name:
|
|
let
|
|
mkColor = name:
|
|
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}";
|
|
|
|
makeKakouneColors = faces:
|
|
concatStringsSep "\n"
|
|
([ "# Generated by home-manager" ]
|
|
++ mapAttrsToList makeKakouneFace faces);
|
|
|
|
writeKakouneConfig = file: config: pkgs.writeText file (makeKakouneColors config);
|
|
|
|
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
|
|
'';
|
|
in
|
|
{
|
|
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 {
|
|
home.packages = mkIf cfg.colors.enable [
|
|
kak-light
|
|
kak-dark
|
|
kak-background
|
|
];
|
|
|
|
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
|
|
}
|
|
'';
|
|
};
|
|
}
|