kitty: allow not setting shell_integration

This allows better support for using kitty's built-in shell integration
method by setting `shellIntegration.mode' to `null', which makes it not
be set at all in the config file and disables modification to shell
initialization scripts by default. If this is used, the user should set
`settings.shell_integration' instead (if shell integration is desired),
which receives no special handling.
This commit is contained in:
MithicSpirit 2024-10-12 21:11:00 -04:00 committed by Austin Horstman
parent a3c9e88177
commit fc3cd1e408
4 changed files with 41 additions and 9 deletions

View file

@ -52,10 +52,11 @@ let
mkShellIntegrationOption = option:
option // {
default =
!(lib.elem "disabled" (lib.splitString " " cfg.shellIntegration.mode));
default = (cfg.shellIntegration.mode != null) && !(lib.elem "disabled"
(lib.splitString " " cfg.shellIntegration.mode));
defaultText = literalExpression ''
!(elem "disabled" (splitString " " config.programs.kitty.shellIntegration.mode))
(cfg.shellIntegration.mode != null)
&& !(elem "disabled" (splitString " " config.programs.kitty.shellIntegration.mode))
'';
};
in {
@ -167,19 +168,19 @@ in {
shellIntegration = {
mode = mkOption {
type = types.str;
type = types.nullOr types.str;
default = "no-rc";
example = "no-cursor";
apply = o:
apply = lib.mapNullable (o:
let
modes = lib.splitString " " o;
filtered = lib.filter (m: m != "no-rc") modes;
in lib.concatStringsSep " "
(lib.concatLists [ [ "no-rc" ] filtered ]);
(lib.concatLists [ [ "no-rc" ] filtered ]));
description = ''
Set the mode of the shell integration. This accepts the same options
as the `shell_integration` option of Kitty. Note that
`no-rc` is always implied. See
`no-rc` is always implied, unless this set to `null`. See
<https://sw.kovidgoyal.net/kitty/shell-integration>
for more details.
'';
@ -219,10 +220,10 @@ in {
(optionalString (cfg.themeFile != null) ''
include ${pkgs.kitty-themes}/share/kitty-themes/themes/${cfg.themeFile}.conf
'')
''
(optionalString (cfg.shellIntegration.mode != null) ''
# Shell integration is sourced and configured manually
shell_integration ${cfg.shellIntegration.mode}
''
'')
(toKittyConfig cfg.settings)
(toKittyKeybindings cfg.keybindings)
(toKittyEnv cfg.environment)