2023-10-26 02:37:42 +00:00
|
|
|
{ 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 \
|
2023-11-03 04:12:17 +00:00
|
|
|
${cfg.colors.colors-path}/"$1".conf &
|
2023-10-26 02:37:42 +00:00
|
|
|
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 = {
|
2023-11-03 04:12:17 +00:00
|
|
|
enable = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2023-10-26 02:37:42 +00:00
|
|
|
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.)
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-11-03 04:12:17 +00:00
|
|
|
colors-path = lib.mkOption {
|
|
|
|
type = lib.types.path;
|
2023-12-23 01:49:53 +00:00
|
|
|
default = "${pkgs.terminal-themes}/kitty";
|
2023-11-03 04:12:17 +00:00
|
|
|
description = "Path from which to load kitty colors.";
|
2023-10-26 02:37:42 +00:00
|
|
|
};
|
|
|
|
|
2023-11-03 04:12:17 +00:00
|
|
|
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;
|
2023-10-26 02:37:42 +00:00
|
|
|
default = "light";
|
|
|
|
description = "The name to use for the light colorscheme.";
|
|
|
|
};
|
|
|
|
|
2023-11-03 04:12:17 +00:00
|
|
|
dark-name = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2023-10-26 02:37:42 +00:00
|
|
|
default = "dark";
|
|
|
|
description = "The name to use for the dark colorscheme.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2023-11-03 04:12:17 +00:00
|
|
|
config = lib.mkIf (cfg.enable && cfg.colors.enable) {
|
|
|
|
home.packages = [ term-light term-dark term-background ];
|
2023-10-26 02:37:42 +00:00
|
|
|
|
2023-11-03 04:12:17 +00:00
|
|
|
programs.kitty.settings = {
|
2023-10-26 02:37:42 +00:00
|
|
|
allow_remote_control = "yes";
|
|
|
|
listen_on = "unix:/tmp/mykitty";
|
|
|
|
};
|
|
|
|
|
2023-11-03 04:12:17 +00:00
|
|
|
xdg.configFile."kitty/macos-launch-services-cmdline".text =
|
|
|
|
lib.mkIf pkgs.stdenv.isDarwin "--listen-on unix:/tmp/mykitty";
|
2023-10-26 02:37:42 +00:00
|
|
|
};
|
|
|
|
}
|