From 7200b8c963748e9d008abc28b96dca34c9336433 Mon Sep 17 00:00:00 2001 From: "Manu [tennox]" Date: Wed, 24 Apr 2024 12:34:36 +0100 Subject: [PATCH] zellij: add config options for autostart from: https://zellij.dev/documentation/integration.html#fish --- modules/programs/zellij.nix | 48 ++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/modules/programs/zellij.nix b/modules/programs/zellij.nix index 079d20c0..0e209c70 100644 --- a/modules/programs/zellij.nix +++ b/modules/programs/zellij.nix @@ -49,15 +49,28 @@ in { default = false; }; - enableFishIntegration = mkEnableOption "Fish integration (enables both enableFishAutostart and enableFishCompletions)" // { - default = false; - }; - enableFishAutostart = mkEnableOption "autostart zellij in interactive sessions" // { - default = false; - }; + enableFishIntegration = mkEnableOption + "Fish integration (enables both enableFishAutoStart and enableFishCompletions)" + // { + default = false; + }; enableFishCompletions = mkEnableOption "load zellij completions" // { default = false; }; + enableFishAutoStart = + mkEnableOption "autostart zellij in interactive sessions" // { + default = false; + }; + autoStartAttachIfSessionExists = mkEnableOption + "If the zellij session already exists, attach to the default session. (requires enableFishAutoStart)" + // { + default = false; + }; + autoStartExitShellOnZellijExit = mkEnableOption + "When zellij exits, exit the shell as well. (requires enableFishAutoStart)" + // { + default = false; + }; }; config = mkIf cfg.enable { @@ -83,15 +96,22 @@ in { eval "$(${zellijCmd} setup --generate-auto-start zsh)" ''); - programs.fish.interactiveShellInit = mkIf (cfg.enableFishIntegration || cfg.enableFishAutostart || cfg.enableFishCompletions) - (mkOrder 200 ( - (if cfg.enableFishIntegration || cfg.enableFishCompletions then '' + home.sessionVariables = { + ZELLIJ_AUTO_ATTACH = + if cfg.autoStartAttachIfSessionExists then "true" else "false"; + ZELLIJ_AUTO_EXIT = + if cfg.autoStartExitShellOnZellijExit then "true" else "false"; + }; + + programs.fish.interactiveShellInit = mkIf (cfg.enableFishIntegration + || cfg.enableFishAutoStart || cfg.enableFishCompletions) (mkOrder 200 + ((if cfg.enableFishIntegration || cfg.enableFishCompletions then '' eval (${zellijCmd} setup --generate-completion fish | string collect) - '' else "") + - (if cfg.enableFishIntegration || cfg.enableFishAutostart then '' - eval (${zellijCmd} setup --generate-auto-start fish | string collect) - '' else "") - )); + '' else + "") + (if cfg.enableFishIntegration || cfg.enableFishAutoStart then '' + eval (${zellijCmd} setup --generate-auto-start fish | string collect) + '' else + ""))); }; }