From 4755a2708955f9e3f8f760c089d4fb2abf3b79c8 Mon Sep 17 00:00:00 2001 From: Noah Masur <7386960+nmasur@users.noreply.github.com> Date: Sun, 27 Jul 2025 10:09:35 -0400 Subject: [PATCH] add zellij session toggle feature --- .../nmasur/presets/programs/zellij.nix | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/platforms/home-manager/modules/nmasur/presets/programs/zellij.nix b/platforms/home-manager/modules/nmasur/presets/programs/zellij.nix index 2cf4ac0..998ad9f 100644 --- a/platforms/home-manager/modules/nmasur/presets/programs/zellij.nix +++ b/platforms/home-manager/modules/nmasur/presets/programs/zellij.nix @@ -7,6 +7,15 @@ let cfg = config.nmasur.presets.programs.zellij; + + zellij-switch-to-last = pkgs.writeShellScriptBin "zellij-switch-to-last" '' + TARGET_SESSION=$(cat ~/.local/state/zellij-last-session) + if [ -z "$TARGET_SESSION" ]; then + return 1 + fi + echo "$ZELLIJ_SESSION_NAME" > ~/.local/state/zellij-last-session + zellij pipe --plugin file:$(which zellij-switch.wasm) -- "--session $TARGET_SESSION" + ''; in { @@ -31,6 +40,7 @@ in if test "$TARGET_DIR" = $(pwd) return 1 end + echo "$ZELLIJ_SESSION_NAME" > ~/.local/state/zellij-last-session zellij pipe --plugin file:$(which zellij-switch.wasm) -- "--cwd $TARGET_DIR --layout default --session $(basename $TARGET_DIR)" ''; }; @@ -69,13 +79,13 @@ in programs.zellij = { enable = true; - enableBashIntegration = true; - enableFishIntegration = true; - enableZshIntegration = true; - # Not yet available in unstable - # attachExistingSession = true; - # exitShellOnExit = true; + # Auto start on shell init + enableBashIntegration = false; + enableFishIntegration = false; + enableZshIntegration = false; + attachExistingSession = false; + exitShellOnExit = false; settings = { default_mode = "locked"; @@ -109,6 +119,14 @@ in }; }; shared = { + "bind \"Alt Shift s\"" = { + Run = { + _args = [ + (lib.getExe zellij-switch-to-last) + ]; + close_on_exit = true; + }; + }; "bind \"Alt Shift p\"" = { Run = { _args = [