1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-12-02 15:11:03 +01:00

zellij: Add additional options for integrating with shells

This commit is contained in:
David Chocholatý 2024-11-03 18:20:23 +01:00 committed by Austin Horstman
parent 908e055e15
commit 0394c71f2b
2 changed files with 73 additions and 13 deletions

View file

@ -8,18 +8,39 @@ let
yamlFormat = pkgs.formats.yaml { };
zellijCmd = getExe cfg.package;
autostartOnShellStartModule = types.submodule {
options = {
enable = mkEnableOption "" // {
description = ''
Whether to autostart Zellij session on shell creation.
'';
};
attachExistingSession = mkEnableOption "" // {
description = ''
Whether to attach to the default session after being autostarted if a Zellij session already exists.
'';
};
exitShellOnExit = mkEnableOption "" // {
description = ''
Whether to exit the shell when Zellij exits after being autostarted.
'';
};
};
};
in {
meta.maintainers = [ hm.maintainers.mainrs ];
options.programs.zellij = {
enable = mkEnableOption "zellij";
enable = mkEnableOption "Zellij";
package = mkOption {
type = types.package;
default = pkgs.zellij;
defaultText = literalExpression "pkgs.zellij";
description = ''
The zellij package to install.
The Zellij package to install.
'';
};
@ -44,6 +65,15 @@ in {
'';
};
autostartOnShellStart = mkOption {
type = types.nullOr autostartOnShellStartModule;
default = null;
description = ''
Options related to autostarting Zellij on shell creation.
Requires enable<Shell>Integration to apply to the respective <Shell>.
'';
};
enableBashIntegration =
lib.hm.shell.mkBashIntegrationOption { inherit config; };
@ -69,17 +99,32 @@ in {
text = lib.hm.generators.toKDL { } cfg.settings;
};
programs.bash.initExtra = mkIf cfg.enableBashIntegration (mkOrder 200 ''
eval "$(${zellijCmd} setup --generate-auto-start bash)"
'');
programs.zsh.initExtra = mkIf (cfg.enableZshIntegration)
(if cfg.autostartOnShellStart.enable then (mkOrder 200 ''
eval "$(${zellijCmd} setup --generate-auto-start zsh)"
'') else
"");
programs.zsh.initContent = mkIf cfg.enableZshIntegration (mkOrder 200 ''
eval "$(${zellijCmd} setup --generate-auto-start zsh)"
'');
programs.fish.interactiveShellInit = mkIf cfg.enableFishIntegration
(mkOrder 200 ''
programs.fish.interactiveShellInit = mkIf (cfg.enableFishIntegration)
(if cfg.autostartOnShellStart.enable then ''
eval (${zellijCmd} setup --generate-auto-start fish | string collect)
'');
'' else
"");
programs.bash.initExtra = mkIf (cfg.enableBashIntegration)
(if cfg.autostartOnShellStart.enable then ''
eval "$(${zellijCmd} setup --generate-auto-start bash)"
'' else
"");
home.sessionVariables = mkIf cfg.autostartOnShellStart.enable {
ZELLIJ_AUTO_ATTACH =
if cfg.autostartOnShellStart.attachExistingSession then
"true"
else
"false";
ZELLIJ_AUTO_EXIT =
if cfg.autostartOnShellStart.exitShellOnExit then "true" else "false";
};
};
}