Skip to content

Commit

Permalink
kitty: add shellIntegration (nix-community#3759)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Scrumplex authored and sysedwinistrator committed May 30, 2023
1 parent 92d78d5 commit 98238b7
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
58 changes: 58 additions & 0 deletions modules/programs/kitty.nix
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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;
};
}
3 changes: 3 additions & 0 deletions tests/modules/programs/kitty/example-settings-expected.conf
Expand Up @@ -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
Expand Down

0 comments on commit 98238b7

Please sign in to comment.