From a4d757079b218f9c50a0f5ae135e82cd032db63d Mon Sep 17 00:00:00 2001 From: Tigor Hutasuhut Date: Thu, 25 Jul 2024 22:28:38 +0700 Subject: [PATCH] home: added zellij implementation --- home/programs/default.nix | 1 + home/programs/zellij.nix | 157 ++++++++++++++++++++++++++++++++++++++ options/programs.nix | 17 +++++ profiles/homeserver.nix | 5 ++ 4 files changed, 180 insertions(+) create mode 100644 home/programs/zellij.nix diff --git a/home/programs/default.nix b/home/programs/default.nix index 8ddae97..7ce0af5 100644 --- a/home/programs/default.nix +++ b/home/programs/default.nix @@ -27,6 +27,7 @@ ./vscode.nix ./whatsapp.nix ./zathura.nix + ./zellij.nix ./zsh.nix ./wezterm diff --git a/home/programs/zellij.nix b/home/programs/zellij.nix new file mode 100644 index 0000000..313db9f --- /dev/null +++ b/home/programs/zellij.nix @@ -0,0 +1,157 @@ +{ config, lib, ... }: +let + cfg = config.profile.home.programs.zellij; +in +{ + config = lib.mkIf cfg.enable { + programs.zellij.enable = true; + + programs.zsh.initExtraFirst = lib.mkOrder 20000 ( + /*bash*/ '' + ZELLIJ_AUTO_EXIT=true + ZELLIJ_AUTO_ATTACH=${toString cfg.autoAttach} + eval "$(zellij setup --generate-auto-start zsh)" + '' + ); + + home.file.".config/zellij/config.kdl".text = /*kdl*/ '' + theme "catppuccin-mocha"; + + keybinds clear-defaults=true { + normal { + bind "Ctrl a" { SwitchToMode "tmux"; } + } + + locked { + bind "Ctrl a" { SwitchToMode "normal"; } + } + + tmux { + // Switching modes + bind "Ctrl a" "Ctrl c" "Esc" { SwitchToMode "Normal"; } + bind "w" { SwitchToMode "Resize"; } + bind "e" { SwitchToMode "Scroll"; } + bind "s" { SwitchToMode "Session"; } + bind "r" { SwitchToMode "RenamePane"; PaneNameInput 0; } + bind "R" { SwitchToMode "RenameTab"; TabNameInput 0; } + bind "/" { SwitchToMode "EnterSearch"; SearchInput 0; } + bind "\\" { SwitchToMode "locked"; } + + + // Pane management + bind "Enter" { NewPane "Right"; SwitchToMode "Normal"; }; + bind "Backspace" { NewPane "Down"; SwitchToMode "Normal"; }; + bind "q" { CloseFocus; SwitchToMode "Normal"; } + bind "h" { MoveFocus "Left"; SwitchToMode "Normal"; } + bind "j" { MoveFocus "Down"; SwitchToMode "Normal"; } + bind "k" { MoveFocus "Up"; SwitchToMode "Normal"; } + bind "l" { MoveFocus "Right"; SwitchToMode "Normal"; } + bind "H" { MovePane "Left"; SwitchToMode "Normal"; } + bind "J" { MovePane "Down"; SwitchToMode "Normal"; } + bind "K" { MovePane "Up"; SwitchToMode "Normal"; } + bind "L" { MovePane "Right"; SwitchToMode "Normal"; } + bind "Space" { ToggleFocusFullscreen; SwitchToMode "Normal"; } + + // Tab management + bind "t" { NewTab; SwitchToMode "Normal"; } + bind "x" { CloseTab; SwitchToMode "Normal"; } + bind "1" { GoToTab 1; SwitchToMode "Normal"; } + bind "2" { GoToTab 2; SwitchToMode "Normal"; } + bind "3" { GoToTab 3; SwitchToMode "Normal"; } + bind "4" { GoToTab 4; SwitchToMode "Normal"; } + bind "5" { GoToTab 5; SwitchToMode "Normal"; } + bind "6" { GoToTab 6; SwitchToMode "Normal"; } + bind "7" { GoToTab 7; SwitchToMode "Normal"; } + bind "8" { GoToTab 8; SwitchToMode "Normal"; } + bind "9" { GoToTab 9; SwitchToMode "Normal"; } + } + + resize { + bind "Ctrl c" "Esc" { SwitchToMode "Normal"; } + bind "h" "Left" { Resize "Increase Left"; } + bind "j" "Down" { Resize "Increase Down"; } + bind "k" "Up" { Resize "Increase Up"; } + bind "l" "Right" { Resize "Increase Right"; } + bind "H" { Resize "Decrease Left"; } + bind "J" { Resize "Decrease Down"; } + bind "K" { Resize "Decrease Up"; } + bind "L" { Resize "Decrease Right"; } + bind "=" "+" { Resize "Increase"; } + bind "-" { Resize "Decrease"; } + } + + search { + bind "/" { SwitchToMode "EnterSearch"; SearchInput 0; } + bind "Ctrl s" { SwitchToMode "Normal"; } + bind "Ctrl c" "Esc" { ScrollToBottom; SwitchToMode "Normal"; } + bind "j" "Down" { ScrollDown; } + bind "k" "Up" { ScrollUp; } + bind "Ctrl f" "PageDown" "Right" "l" { PageScrollDown; } + bind "Ctrl b" "PageUp" "Left" "h" { PageScrollUp; } + bind "d" { HalfPageScrollDown; } + bind "u" { HalfPageScrollUp; } + bind "n" { Search "down"; } + bind "p" { Search "up"; } + bind "c" { SearchToggleOption "CaseSensitivity"; } + bind "w" { SearchToggleOption "Wrap"; } + bind "o" { SearchToggleOption "WholeWord"; } + } + + entersearch { + bind "Ctrl c" "Esc" { SwitchToMode "Scroll"; } + bind "Enter" { SwitchToMode "Search"; } + } + + scroll { + bind "Esc" { SwitchToMode "Normal"; } + bind "e" { EditScrollback; SwitchToMode "Normal"; } + bind "/" { SwitchToMode "EnterSearch"; SearchInput 0; } + bind "Ctrl c" { ScrollToBottom; SwitchToMode "Normal"; } + bind "j" "Down" { ScrollDown; } + bind "k" "Up" { ScrollUp; } + bind "Ctrl f" "PageDown" "Right" "l" { PageScrollDown; } + bind "Ctrl b" "PageUp" "Left" "h" { PageScrollUp; } + bind "d" { HalfPageScrollDown; } + bind "u" { HalfPageScrollUp; } + } + + session { + bind "Ctrl c" "Esc" { SwitchToMode "Normal"; } + bind "d" { Detach; } + bind "s" { + LaunchOrFocusPlugin "session-manager" { + floating true + move_to_focused_tab true + }; + SwitchToMode "Normal" + } + bind "c" { + LaunchOrFocusPlugin "configuration" { + floating true + move_to_focused_tab true + }; + SwitchToMode "Normal" + } + } + + renametab { + bind "Ctrl c" "Esc" { SwitchToMode "Normal"; } + // bind "Esc" { UndoRenameTab; SwitchToMode "Tab"; } + } + renamepane { + bind "Ctrl c" "Esc" { SwitchToMode "Normal"; } + // bind "Esc" { UndoRenamePane; SwitchToMode "Pane"; } + } + + // Unused modes is only given escape keys to return to normal mode. + pane { + bind "Ctrl c" "Esc" { SwitchToMode "Normal"; } + } + + move { + bind "Ctrl c" "Esc" { SwitchToMode "Normal"; } + } + } + ''; + }; +} diff --git a/options/programs.nix b/options/programs.nix index 8ffb2ca..208b1f1 100644 --- a/options/programs.nix +++ b/options/programs.nix @@ -74,6 +74,23 @@ home.programs = { zathura.enable = lib.mkEnableOption "zathura"; floorp.enable = lib.mkEnableOption "floorp"; + zellij = { + enable = lib.mkEnableOption "zellij"; + + # Wether to enable auto attach to zellij sessions. + # + # Best used for servers when you want to auto attach to a session when ssh + # into a server. + # + # Desktop usage is not recommended since uses typically have multiple + # terminal windows open and it can be confusing to have a terminal + # window auto attach to a zellij session. + # + # Also, there is resurrections features that zellij offers. + # So desktop user can just resurrect the session if they want to. + autoAttach = lib.mkEnableOption "zellij autoAttach"; + }; + }; programs = { diff --git a/profiles/homeserver.nix b/profiles/homeserver.nix index 1002fca..2ef51e3 100644 --- a/profiles/homeserver.nix +++ b/profiles/homeserver.nix @@ -44,6 +44,11 @@ enable = false; }; + home.programs.zellij = { + enable = true; + autoAttach = true; + }; + services = { caddy.enable = true; cockpit.enable = true;