From a835096fd2bcc369f57b76b9b17cc00348f595f5 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Fri, 12 May 2023 11:20:22 +0200 Subject: [PATCH] kitty: add shellIntegration (#3759) Kitty provides integrations for bash, fish and zsh. The new programs.kitty.shellIntegration options allow the configuration of these integrations. See for more details. Signed-off-by: Sefa Eyeoglu --- modules/programs/kitty.nix | 58 +++++++++++++++++++ .../kitty/example-settings-expected.conf | 3 + 2 files changed, 61 insertions(+) diff --git a/modules/programs/kitty.nix b/modules/programs/kitty.nix index 968522dd8..7cf255890 100644 --- a/modules/programs/kitty.nix +++ b/modules/programs/kitty.nix @@ -26,6 +26,33 @@ let toKittyEnv = generators.toKeyValue { mkKeyValue = name: value: "env ${name}=${value}"; }; + shellIntegrationInit = { + bash = '' + if test -n "$KITTY_INSTALLATION_DIR"; then + source "$KITTY_INSTALLATION_DIR/shell-integration/bash/kitty.bash" + fi + ''; + fish = '' + if set -q KITTY_INSTALLATION_DIR + source "$KITTY_INSTALLATION_DIR/shell-integration/fish/vendor_conf.d/kitty-shell-integration.fish" + set --prepend fish_complete_path "$KITTY_INSTALLATION_DIR/shell-integration/fish/vendor_completions.d" + end + ''; + zsh = '' + if test -n "$KITTY_INSTALLATION_DIR"; then + autoload -Uz -- "$KITTY_INSTALLATION_DIR"/shell-integration/zsh/kitty-integration + kitty-integration + unfunction kitty-integration + fi + ''; + }; + + shellIntegrationDefaultOpt = { + default = cfg.shellIntegration.mode != "disabled"; + defaultText = literalExpression '' + config.programs.kitty.shellIntegration.mode != "disabled" + ''; + }; in { options.programs.kitty = { enable = mkEnableOption "Kitty terminal emulator"; @@ -111,6 +138,27 @@ in { ''; }; + shellIntegration = { + mode = mkOption { + type = types.str; + default = "enabled"; + 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 + + for more details. + ''; + example = "no-cursor"; + }; + enableBashIntegration = mkEnableOption "Kitty bash integration" + // shellIntegrationDefaultOpt; + enableFishIntegration = mkEnableOption "Kitty fish integration" + // shellIntegrationDefaultOpt; + enableZshIntegration = mkEnableOption "Kitty zsh integration" + // shellIntegrationDefaultOpt; + }; + extraConfig = mkOption { default = ""; type = types.lines; @@ -140,6 +188,10 @@ in { "${pkgs.kitty-themes}/share/kitty-themes/themes.json")))).file } '') + '' + # Shell integration is sourced and configured manually + shell_integration no-rc ${cfg.shellIntegration.mode} + '' (toKittyConfig cfg.settings) (toKittyKeybindings cfg.keybindings) (toKittyEnv cfg.environment) @@ -155,5 +207,11 @@ in { (cfg.darwinLaunchOptions != null && pkgs.stdenv.hostPlatform.isDarwin) { text = concatStringsSep " " cfg.darwinLaunchOptions; }; + programs.bash.initExtra = + mkIf cfg.shellIntegration.enableBashIntegration shellIntegrationInit.bash; + programs.fish.interactiveShellInit = + mkIf cfg.shellIntegration.enableFishIntegration shellIntegrationInit.fish; + programs.zsh.initExtra = + mkIf cfg.shellIntegration.enableZshIntegration shellIntegrationInit.zsh; }; } diff --git a/tests/modules/programs/kitty/example-settings-expected.conf b/tests/modules/programs/kitty/example-settings-expected.conf index 31d2fdc12..41a209eae 100644 --- a/tests/modules/programs/kitty/example-settings-expected.conf +++ b/tests/modules/programs/kitty/example-settings-expected.conf @@ -4,6 +4,9 @@ font_family DejaVu Sans font_size 8 +# Shell integration is sourced and configured manually +shell_integration no-rc enabled + enable_audio_bell no scrollback_lines 10000 update_check_interval 0