From 9147a68f0b5e35c2072c3ee3dfc405c5af949634 Mon Sep 17 00:00:00 2001 From: Timo Boomers Date: Thu, 1 May 2025 18:50:16 +0200 Subject: [PATCH] Reconfigured zellij configuration --- hosts/ti-clt-dsk01/default.nix | 1 + modules/home/applications/zellij.nix | 41 +++++++++++++++++++++++++- modules/system/applications/common.nix | 1 + 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/hosts/ti-clt-dsk01/default.nix b/hosts/ti-clt-dsk01/default.nix index 3e8dce7..90b4e20 100644 --- a/hosts/ti-clt-dsk01/default.nix +++ b/hosts/ti-clt-dsk01/default.nix @@ -87,6 +87,7 @@ "share.tbmrs.nl" "vault.local.tbmrs.nl" "paperless.local.tbmrs.nl" + "monitor.local.tbmrs.nl" ]; }; diff --git a/modules/home/applications/zellij.nix b/modules/home/applications/zellij.nix index 00449b0..e541510 100644 --- a/modules/home/applications/zellij.nix +++ b/modules/home/applications/zellij.nix @@ -1,9 +1,38 @@ -{ config, lib, ... }: +{ config, lib, pkgs, ... }: with lib; let cfg = config.settings.applications.zellij; + sesh = pkgs.writeScriptBin "sesh" '' + #! /usr/bin/env sh + + # Taken from https://github.com/zellij-org/zellij/issues/884#issuecomment-1851136980 + # select a directory using zoxide + ZOXIDE_RESULT=$(${pkgs.zoxide}/bin/zoxide query --interactive) + + # checks whether a directory has been selected + if [[ -z "$ZOXIDE_RESULT" ]]; then + # if there was no directory, select returns without executing + exit 0 + fi + # extracts the directory name from the absolute path + SESSION_TITLE=$(echo "$ZOXIDE_RESULT" | sed 's#.*/##') + + # get the list of sessions + SESSION_LIST=$(zellij list-sessions -n | awk '{print $1}') + + # checks if SESSION_TITLE is in the session list + if echo "$SESSION_LIST" | grep -q "^$SESSION_TITLE$"; then + # if so, attach to existing session + zellij attach "$SESSION_TITLE" + else + # if not, create a new session + echo "Creating new session $SESSION_TITLE and CD $ZOXIDE_RESULT" + cd $ZOXIDE_RESULT + zellij attach -c "$SESSION_TITLE" + fi + ''; in { options = { settings.applications.zellij.enable = lib.mkOption { @@ -19,6 +48,15 @@ in { enable = true; }; + programs.zoxide = { + enable = true; + enableZshIntegration = true; + }; + + home.packages = [ + sesh + ]; + home.file.zellij = { target = ".config/zellij/config.kdl"; text = '' @@ -26,6 +64,7 @@ in { keybinds { normal { bind "Ctrl e" { ToggleFloatingPanes; SwitchToMode "normal"; } + bind "Ctrl d" { Detach; } bind "Alt 1" { GoToTab 1; } bind "Alt 2" { GoToTab 2; } bind "Alt 3" { GoToTab 3; } diff --git a/modules/system/applications/common.nix b/modules/system/applications/common.nix index 512e7eb..4f4b777 100644 --- a/modules/system/applications/common.nix +++ b/modules/system/applications/common.nix @@ -22,6 +22,7 @@ in { btop git yazi + zoxide just ];