1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-11-22 18:29:39 +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 { }; yamlFormat = pkgs.formats.yaml { };
zellijCmd = getExe cfg.package; 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 { in {
meta.maintainers = [ hm.maintainers.mainrs ]; meta.maintainers = [ hm.maintainers.mainrs ];
options.programs.zellij = { options.programs.zellij = {
enable = mkEnableOption "zellij"; enable = mkEnableOption "Zellij";
package = mkOption { package = mkOption {
type = types.package; type = types.package;
default = pkgs.zellij; default = pkgs.zellij;
defaultText = literalExpression "pkgs.zellij"; defaultText = literalExpression "pkgs.zellij";
description = '' 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 = enableBashIntegration =
lib.hm.shell.mkBashIntegrationOption { inherit config; }; lib.hm.shell.mkBashIntegrationOption { inherit config; };
@ -69,17 +99,32 @@ in {
text = lib.hm.generators.toKDL { } cfg.settings; text = lib.hm.generators.toKDL { } cfg.settings;
}; };
programs.bash.initExtra = mkIf cfg.enableBashIntegration (mkOrder 200 '' programs.zsh.initExtra = mkIf (cfg.enableZshIntegration)
eval "$(${zellijCmd} setup --generate-auto-start bash)" (if cfg.autostartOnShellStart.enable then (mkOrder 200 ''
''); eval "$(${zellijCmd} setup --generate-auto-start zsh)"
'') else
"");
programs.zsh.initContent = mkIf cfg.enableZshIntegration (mkOrder 200 '' programs.fish.interactiveShellInit = mkIf (cfg.enableFishIntegration)
eval "$(${zellijCmd} setup --generate-auto-start zsh)" (if cfg.autostartOnShellStart.enable then ''
'');
programs.fish.interactiveShellInit = mkIf cfg.enableFishIntegration
(mkOrder 200 ''
eval (${zellijCmd} setup --generate-auto-start fish | string collect) 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";
};
}; };
} }

View file

@ -4,9 +4,16 @@
programs = { programs = {
zellij = { zellij = {
enable = true; enable = true;
enableBashIntegration = true;
autostartOnShellStart = {
enable = true;
attachExistingSession = true;
exitShellOnExit = true;
};
enableZshIntegration = true; enableZshIntegration = true;
enableFishIntegration = true; enableFishIntegration = true;
enableBashIntegration = true;
}; };
bash.enable = true; bash.enable = true;
zsh.enable = true; zsh.enable = true;
@ -32,5 +39,13 @@
assertFileContains \ assertFileContains \
home-files/.config/fish/config.fish \ home-files/.config/fish/config.fish \
'eval (@zellij@/bin/zellij setup --generate-auto-start fish | string collect)' 'eval (@zellij@/bin/zellij setup --generate-auto-start fish | string collect)'
assertFileExists home-path/etc/profile.d/hm-session-vars.sh
assertFileContains \
home-path/etc/profile.d/hm-session-vars.sh \
'export ZELLIJ_AUTO_ATTACH="true"'
assertFileContains \
home-path/etc/profile.d/hm-session-vars.sh \
'export ZELLIJ_AUTO_EXIT="true"'
''; '';
} }