mirror of
https://github.com/nix-community/home-manager.git
synced 2025-12-18 06:51:10 +01:00
zellij: refactor implementation
This commit is contained in:
parent
0394c71f2b
commit
6d4148df8e
2 changed files with 45 additions and 57 deletions
|
|
@ -3,32 +3,8 @@
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
cfg = config.programs.zellij;
|
cfg = config.programs.zellij;
|
||||||
yamlFormat = pkgs.formats.yaml { };
|
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 {
|
in {
|
||||||
meta.maintainers = [ hm.maintainers.mainrs ];
|
meta.maintainers = [ hm.maintainers.mainrs ];
|
||||||
|
|
||||||
|
|
@ -65,12 +41,23 @@ in {
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
autostartOnShellStart = mkOption {
|
attachExistingSession = mkOption {
|
||||||
type = types.nullOr autostartOnShellStartModule;
|
type = types.bool;
|
||||||
default = null;
|
default = false;
|
||||||
description = ''
|
description = ''
|
||||||
Options related to autostarting Zellij on shell creation.
|
Whether to attach to the default session after being autostarted if a Zellij session already exists.
|
||||||
Requires enable<Shell>Integration to apply to the respective <Shell>.
|
|
||||||
|
Variable is checked in `auto-start` script. Requires shell integration to be enabled to have effect.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
exitShellOnExit = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
description = ''
|
||||||
|
Whether to exit the shell when Zellij exits after being autostarted.
|
||||||
|
|
||||||
|
Variable is checked in `auto-start` script. Requires shell integration to be enabled to have effect.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -84,7 +71,10 @@ in {
|
||||||
lib.hm.shell.mkZshIntegrationOption { inherit config; };
|
lib.hm.shell.mkZshIntegrationOption { inherit config; };
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = let
|
||||||
|
shellIntegrationEnabled = (cfg.enableBashIntegration
|
||||||
|
|| cfg.enableZshIntegration || cfg.enableFishIntegration);
|
||||||
|
in mkIf cfg.enable {
|
||||||
home.packages = [ cfg.package ];
|
home.packages = [ cfg.package ];
|
||||||
|
|
||||||
# Zellij switched from yaml to KDL in version 0.32.0:
|
# Zellij switched from yaml to KDL in version 0.32.0:
|
||||||
|
|
@ -99,32 +89,33 @@ in {
|
||||||
text = lib.hm.generators.toKDL { } cfg.settings;
|
text = lib.hm.generators.toKDL { } cfg.settings;
|
||||||
};
|
};
|
||||||
|
|
||||||
programs.zsh.initExtra = mkIf (cfg.enableZshIntegration)
|
programs.bash.initExtra = mkIf cfg.enableBashIntegration ''
|
||||||
(if cfg.autostartOnShellStart.enable then (mkOrder 200 ''
|
eval "$(${getExe cfg.package} setup --generate-auto-start bash)"
|
||||||
eval "$(${zellijCmd} setup --generate-auto-start zsh)"
|
'';
|
||||||
'') else
|
|
||||||
"");
|
|
||||||
|
|
||||||
programs.fish.interactiveShellInit = mkIf (cfg.enableFishIntegration)
|
programs.zsh.initExtra = mkIf cfg.enableZshIntegration (mkOrder 200''
|
||||||
(if cfg.autostartOnShellStart.enable then ''
|
eval "$(${getExe cfg.package} setup --generate-auto-start zsh)"
|
||||||
eval (${zellijCmd} setup --generate-auto-start fish | string collect)
|
'');
|
||||||
'' else
|
|
||||||
"");
|
|
||||||
|
|
||||||
programs.bash.initExtra = mkIf (cfg.enableBashIntegration)
|
programs.fish.interactiveShellInit = mkIf cfg.enableFishIntegration ''
|
||||||
(if cfg.autostartOnShellStart.enable then ''
|
eval (${
|
||||||
eval "$(${zellijCmd} setup --generate-auto-start bash)"
|
getExe cfg.package
|
||||||
'' else
|
} setup --generate-auto-start fish | string collect)
|
||||||
"");
|
'';
|
||||||
|
|
||||||
home.sessionVariables = mkIf cfg.autostartOnShellStart.enable {
|
home.sessionVariables = mkIf shellIntegrationEnabled {
|
||||||
ZELLIJ_AUTO_ATTACH =
|
ZELLIJ_AUTO_ATTACH =
|
||||||
if cfg.autostartOnShellStart.attachExistingSession then
|
if cfg.attachExistingSession then "true" else "false";
|
||||||
"true"
|
ZELLIJ_AUTO_EXIT = if cfg.exitShellOnExit then "true" else "false";
|
||||||
else
|
|
||||||
"false";
|
|
||||||
ZELLIJ_AUTO_EXIT =
|
|
||||||
if cfg.autostartOnShellStart.exitShellOnExit then "true" else "false";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
warnings =
|
||||||
|
optional (cfg.attachExistingSession && !shellIntegrationEnabled) ''
|
||||||
|
You have enabled `programs.zellij.attachExistingSession`, but none of the shell integrations are enabled.
|
||||||
|
This option will have no effect.
|
||||||
|
'' ++ optional (cfg.exitShellOnExit && !shellIntegrationEnabled) ''
|
||||||
|
You have enabled `programs.zellij.exitShellOnExit`, but none of the shell integrations are enabled.
|
||||||
|
This option will have no effect.
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,8 @@
|
||||||
zellij = {
|
zellij = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
||||||
autostartOnShellStart = {
|
attachExistingSession = true;
|
||||||
enable = true;
|
exitShellOnExit = true;
|
||||||
attachExistingSession = true;
|
|
||||||
exitShellOnExit = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
enableZshIntegration = true;
|
enableZshIntegration = true;
|
||||||
enableFishIntegration = true;
|
enableFishIntegration = true;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue