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

78 lines
2.4 KiB
Nix

{ config, pkgs, lib, ... }:
let
cfg = config.programs.kitty;
# helper scripts for changing kitty colors
term-background = pkgs.writeShellScriptBin "term-background" ''
# Accepts the name of a theme file in color-pkg
# If shell is running in a Kitty window set the colors.
if [ -n "$KITTY_WINDOW_ID" ]; then
kitty @ --to $KITTY_LISTEN_ON set-colors --all --configured \
${cfg.colors.colors-path}/"$1".conf &
fi
'';
term-light = pkgs.writeShellScriptBin "term-light" ''
${term-background}/bin/term-background ${cfg.colors.light-name}
'';
term-dark = pkgs.writeShellScriptBin "term-dark" ''
${term-background}/bin/term-background ${cfg.colors.dark-name}
'';
in {
options.programs.kitty = {
colors = {
enable = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''
When enabled, commands <command>term-dark</command> and <command>term-light</command>
will toggle between your dark and a light colors.
There is also <command>term-background</command> which accepts one argument, the name
of the theme.
(Note that the Kitty setting <literal>allow_remote_control = true</literal> is set to
enable this functionality.)
'';
};
colors-path = lib.mkOption {
type = lib.types.path;
default = "${pkgs.terminal-themes}/kitty";
description = "Path from which to load kitty colors.";
};
color-pkg-path = lib.mkOption {
type = lib.types.optional lib.types.path;
default = null;
description = ''
Path to kitty colors within <literal>color-pkgs</literal>.
'';
};
light-name = lib.mkOption {
type = lib.types.str;
default = "light";
description = "The name to use for the light colorscheme.";
};
dark-name = lib.mkOption {
type = lib.types.str;
default = "dark";
description = "The name to use for the dark colorscheme.";
};
};
};
config = lib.mkIf (cfg.enable && cfg.colors.enable) {
home.packages = [ term-light term-dark term-background ];
programs.kitty.settings = {
allow_remote_control = "yes";
listen_on = "unix:/tmp/mykitty";
};
xdg.configFile."kitty/macos-launch-services-cmdline".text =
lib.mkIf pkgs.stdenv.isDarwin "--listen-on unix:/tmp/mykitty";
};
}