1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2025-01-30 21:05:02 +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
parent 5ad12b6ea0
commit b87b657770
No known key found for this signature in database
GPG key ID: 8FC8E68432148DCA

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.
'';
};
@ -41,6 +62,17 @@ in {
'';
};
# Additional options.
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>.
'';
};
# Shell integration.
enableBashIntegration = mkEnableOption "Bash integration" // {
default = false;
};
@ -69,17 +101,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 ''
eval "$(${zellijCmd} setup --generate-auto-start zsh)"
'' else
"");
programs.zsh.initExtra = 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";
};
};
}