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 <https://sw.kovidgoyal.net/kitty/shell-integration> for more details.

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
Sefa Eyeoglu 2023-05-12 11:20:22 +02:00 committed by GitHub
parent cc9f65d104
commit a835096fd2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 61 additions and 0 deletions

View file

@ -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
<link xlink:href="https://sw.kovidgoyal.net/kitty/shell-integration"/>
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;
};
}

View file

@ -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