From 8f3d8dec2645ab80680a357d183adad5bb430353 Mon Sep 17 00:00:00 2001 From: MithicSpirit Date: Sat, 12 Oct 2024 21:11:00 -0400 Subject: [PATCH] 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. --- modules/programs/kitty.nix | 19 ++++++++-------- tests/modules/programs/kitty/default.nix | 1 + .../kitty/null-shellIntegration-expected.conf | 8 +++++++ .../programs/kitty/null-shellIntegration.nix | 22 +++++++++++++++++++ 4 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 tests/modules/programs/kitty/null-shellIntegration-expected.conf create mode 100644 tests/modules/programs/kitty/null-shellIntegration.nix diff --git a/modules/programs/kitty.nix b/modules/programs/kitty.nix index 9854fe69c..3d279c037 100644 --- a/modules/programs/kitty.nix +++ b/modules/programs/kitty.nix @@ -49,10 +49,11 @@ let ''; }; - shellIntegrationDefaultOpt = { - default = !(elem "disabled" (splitString " " cfg.shellIntegration.mode)); + shellIntegrationDefaultOpt = let mode = cfg.shellIntegration.mode; + in { + default = (mode != null) && !(elem "disabled" (splitString " " mode)); defaultText = literalExpression '' - !(elem "disabled" (splitString " " config.programs.kitty.shellIntegration.mode)) + (mode != null) && !(elem "disabled" (splitString " " config.programs.kitty.shellIntegration.mode)) ''; }; in { @@ -162,18 +163,18 @@ in { shellIntegration = { mode = mkOption { - type = types.str; + type = types.nullOr types.str; default = "no-rc"; example = "no-cursor"; - apply = o: + apply = mapNullable (o: let modes = splitString " " o; filtered = filter (m: m != "no-rc") modes; - in concatStringsSep " " (concatLists [ [ "no-rc" ] filtered ]); + in concatStringsSep " " (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 for more details. ''; @@ -213,10 +214,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) diff --git a/tests/modules/programs/kitty/default.nix b/tests/modules/programs/kitty/default.nix index 76016d516..054353e43 100644 --- a/tests/modules/programs/kitty/default.nix +++ b/tests/modules/programs/kitty/default.nix @@ -1,4 +1,5 @@ { kitty-example-settings = ./example-settings.nix; kitty-theme-to-themeFile = ./theme-to-themeFile.nix; + kitty-null-shellIntegration = ./null-shellIntegration.nix; } diff --git a/tests/modules/programs/kitty/null-shellIntegration-expected.conf b/tests/modules/programs/kitty/null-shellIntegration-expected.conf new file mode 100644 index 000000000..df3ae5984 --- /dev/null +++ b/tests/modules/programs/kitty/null-shellIntegration-expected.conf @@ -0,0 +1,8 @@ +# Generated by Home Manager. +# See https://sw.kovidgoyal.net/kitty/conf.html + + + + + + diff --git a/tests/modules/programs/kitty/null-shellIntegration.nix b/tests/modules/programs/kitty/null-shellIntegration.nix new file mode 100644 index 000000000..293249d69 --- /dev/null +++ b/tests/modules/programs/kitty/null-shellIntegration.nix @@ -0,0 +1,22 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + programs.kitty = { + enable = true; + + shellIntegration.mode = null; + }; + + test.stubs.kitty = { }; + + nmt.script = '' + assertFileExists home-files/.config/kitty/kitty.conf + assertFileContent \ + home-files/.config/kitty/kitty.conf \ + ${./null-shellIntegration-expected.conf} + ''; + }; +}