From ec8d0d24326bc62e6ceb125a73b4c8224e8e03fa Mon Sep 17 00:00:00 2001 From: elwrcl Date: Sat, 5 Sep 2026 03:22:47 +0300 Subject: [PATCH] zellij --- .../zellij/home-zellij-ide-command.ulu.nix | 39 ++++++----- .../home/zellij/home-zellij-keybinds.ulu.nix | 7 ++ .../zellij/home-zellij-layout-ide.ulu.nix | 70 ++++++++++++++++++- modules/home/zellij/home-zellij.ulu.nix | 3 +- 4 files changed, 97 insertions(+), 22 deletions(-) diff --git a/modules/home/zellij/home-zellij-ide-command.ulu.nix b/modules/home/zellij/home-zellij-ide-command.ulu.nix index d5a92a2..5c072cf 100644 --- a/modules/home/zellij/home-zellij-ide-command.ulu.nix +++ b/modules/home/zellij/home-zellij-ide-command.ulu.nix @@ -9,29 +9,34 @@ runtimeInputs = [ config.programs.zellij.finalPackage pkgs.coreutils - pkgs.gnugrep + pkgs.gawk ]; text = '' - case "''${1:-}" in - -h | --help) - echo "usage: ide [directory]" - echo - echo "opens re-attaches to a Zellij session named after the" - echo "directory, running Helix in the 'ide' layout." - exit 0 - ;; - esac + case "''${1:-}" in + -h | --help) + echo "usage: ide [directory]" + echo + echo "opens re-attaches to a Zellij session named after the" + echo "directory, running Helix in the 'ide' layout." + exit 0 + ;; + esac - cd "''${1:-.}" + cd "''${1:-.}" - session=$(basename "$PWD") - session=$(printf '%s' "$session" | tr -c 'A-Za-z0-9._-' '-') + session=$(basename "$PWD") + session=$(printf '%s' "$session" | tr -c 'A-Za-z0-9._-' '-') - if zellij list-sessions --short 2>/dev/null | grep -qx "$session"; then - exec zellij attach "$session" - fi + if zellij list-sessions --no-formatting 2>/dev/null | + awk -v s="$session" '$1 == s && $0 !~ /EXITED/ { hit = 1 } END { exit !hit }'; then + exec zellij attach "$session" + fi - exec zellij --session "$session" --new-session-with-layout ide + # Drop any dead session squatting on the name so the layout is rebuilt + # from scratch rather than resurrected. + zellij delete-session "$session" >/dev/null 2>&1 || true + + exec zellij --session "$session" --new-session-with-layout ide ''; }) ]; diff --git a/modules/home/zellij/home-zellij-keybinds.ulu.nix b/modules/home/zellij/home-zellij-keybinds.ulu.nix index 6023e98..2a73096 100644 --- a/modules/home/zellij/home-zellij-keybinds.ulu.nix +++ b/modules/home/zellij/home-zellij-keybinds.ulu.nix @@ -18,6 +18,11 @@ } } + bind "Alt h" { MoveFocusOrTab "Left"; } + bind "Alt l" { MoveFocusOrTab "Right"; } + bind "Alt k" { MoveFocus "Up"; } + bind "Alt j" { MoveFocus "Down"; } + // tabs bind "Alt t" { NewTab; } bind "Alt 1" { GoToTab 1; } @@ -65,6 +70,7 @@ // tabs bind "c" { NewTab; SwitchToMode "Normal"; } bind "," { SwitchToMode "RenameTab"; TabNameInput 0; } + bind "." { SwitchToMode "RenamePane"; PaneNameInput 0; } bind "X" { CloseTab; SwitchToMode "Normal"; } bind "p" { GoToPreviousTab; SwitchToMode "Normal"; } bind "b" { BreakPane; SwitchToMode "Normal"; } @@ -81,6 +87,7 @@ // sub-modes bind "r" { SwitchToMode "Resize"; } + bind "Ctrl l" { SwitchToMode "Locked"; } bind "[" { SwitchToMode "Scroll"; } bind "/" { SwitchToMode "EnterSearch"; SearchInput 0; } diff --git a/modules/home/zellij/home-zellij-layout-ide.ulu.nix b/modules/home/zellij/home-zellij-layout-ide.ulu.nix index 1f23f33..70b1ca5 100644 --- a/modules/home/zellij/home-zellij-layout-ide.ulu.nix +++ b/modules/home/zellij/home-zellij-layout-ide.ulu.nix @@ -1,20 +1,66 @@ { ... }: { flake.homeModules.home-zellij-layout-ide = - { ... }: + { + config, + lib, + pkgs, + ... + }: + let + p = config.elars.theme.palette; + c = hex: "#${hex}"; + bg = c p.base00; + bgAlt = c p.base01; + dim = c p.base03; + muted = c p.base04; + accent = c p.accent; + + mode = + key: background: label: + ''mode_${key} "#[bg=${background},fg=${bg},bold] ${label} "''; + + modes = lib.concatStringsSep "\n " [ + (mode "normal" (c p.base0B) "NORMAL") + (mode "tmux" (c p.base09) "ZELLIJ") + (mode "locked" dim "LOCKED") + (mode "resize" (c p.base0D) "RESIZE") + (mode "scroll" (c p.base0C) "SCROLL") + (mode "search" (c p.base0C) "SEARCH") + (mode "entersearch" (c p.base0C) "SEARCH") + (mode "renametab" (c p.base0E) "RENAME") + (mode "renamepane" (c p.base0E) "RENAME") + ]; + in { programs.zellij.layouts.ide = '' layout { default_tab_template { pane size=1 borderless=true { - plugin location="zellij:compact-bar" + plugin location="file:${pkgs.zellijPlugins.zjstatus}" { + format_left "{mode}#[bg=${bgAlt},fg=${accent},bold] {session} #[bg=${bg}] {tabs}" + format_right "#[bg=${bg},fg=${dim}]{swap_layout} {datetime}" + format_space "#[bg=${bg}]" + + border_enabled "false" + hide_frame_for_single_pane "false" + + ${modes} + + tab_normal "#[bg=${bgAlt},fg=${muted}] {index} {name} " + tab_active "#[bg=${accent},fg=${bg},bold] {index} {name} " + + datetime "#[bg=${bg},fg=${muted},bold] {format} " + datetime_format "%H:%M" + datetime_timezone "Europe/Istanbul" + } } children } tab name="edit" focus=true { pane split_direction="vertical" { - pane size="20%" name="files" command="hx-sidebar" close_on_exit=true { + pane size=40 name="files" command="hx-sidebar" close_on_exit=true { args "." } pane focus=true command="hx" close_on_exit=true @@ -29,6 +75,24 @@ } } } + + swap_tiled_layout name="vertical" { + tab { + pane split_direction="vertical" { children; } + } + } + + swap_tiled_layout name="horizontal" { + tab { + pane split_direction="horizontal" { children; } + } + } + + swap_tiled_layout name="stacked" { + tab { + pane stacked=true { children; } + } + } } ''; }; diff --git a/modules/home/zellij/home-zellij.ulu.nix b/modules/home/zellij/home-zellij.ulu.nix index d759b1a..e5e6773 100644 --- a/modules/home/zellij/home-zellij.ulu.nix +++ b/modules/home/zellij/home-zellij.ulu.nix @@ -21,8 +21,7 @@ stacked_resize = true; scroll_buffer_size = 50000; scrollback_editor = "hx"; - session_serialization = true; - serialize_pane_viewport = true; + session_serialization = false; on_force_close = "detach"; show_startup_tips = false; show_release_notes = false;