From b901b9abd9e9b4bcdcf48542e1c575a2dafbba20 Mon Sep 17 00:00:00 2001 From: Noah Masur <7386960+nmasur@users.noreply.github.com> Date: Sun, 23 Mar 2025 10:10:52 -0400 Subject: [PATCH] zellij tweaks and session switching --- flake.lock | 72 ++++++++++++++++ flake.nix | 6 ++ lib/default.nix | 1 + .../nmasur/presets/programs/ghostty.nix | 7 ++ .../nmasur/presets/programs/zellij.nix | 84 ++++++++++++++++++- .../modules/nmasur/profiles/darwin-base.nix | 2 + .../modules/nmasur/profiles/experimental.nix | 2 + .../modules/nmasur/profiles/power-user.nix | 19 +++-- 8 files changed, 183 insertions(+), 10 deletions(-) diff --git a/flake.lock b/flake.lock index 43ca9c7..e9c6a7c 100644 --- a/flake.lock +++ b/flake.lock @@ -334,6 +334,22 @@ "type": "github" } }, + "nixpkgs_2": { + "locked": { + "lastModified": 1728538411, + "narHash": "sha256-f0SBJz1eZ2yOuKUr5CA9BHULGXVSn6miBuUWdTyhUhU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b69de56fac8c2b6f8fd27f2eca01dcda8e0a4221", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, "nur": { "inputs": { "flake-parts": "flake-parts", @@ -372,9 +388,28 @@ "nixpkgs-stable": "nixpkgs-stable", "nur": "nur", "wsl": "wsl", + "zellij-switch": "zellij-switch", "zenyd-mpv-scripts": "zenyd-mpv-scripts" } }, + "rust-overlay": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1736476219, + "narHash": "sha256-+qyv3QqdZCdZ3cSO/cbpEY6tntyYjfe1bB12mdpNFaY=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "de30cc5963da22e9742bbbbb9a3344570ed237b9", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, "systems": { "locked": { "lastModified": 1689347925, @@ -405,6 +440,21 @@ "type": "github" } }, + "systems_3": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, "treefmt-nix": { "inputs": { "nixpkgs": [ @@ -447,6 +497,28 @@ "type": "github" } }, + "zellij-switch": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-overlay": "rust-overlay", + "systems": "systems_3" + }, + "locked": { + "lastModified": 1737011317, + "narHash": "sha256-A8VGuw/jIw+NCo5aCYy8MFrWpKzZLf77RApGGMzHxCY=", + "owner": "mostafaqanbaryan", + "repo": "zellij-switch", + "rev": "15b02834c8be735fca0d9fb41f48709f97cc9afc", + "type": "github" + }, + "original": { + "owner": "mostafaqanbaryan", + "repo": "zellij-switch", + "type": "github" + } + }, "zenyd-mpv-scripts": { "flake": false, "locked": { diff --git a/flake.nix b/flake.nix index 4909155..04175f7 100644 --- a/flake.nix +++ b/flake.nix @@ -64,6 +64,12 @@ flake = false; }; + # Zellij Switcher + zellij-switch = { + url = "github:mostafaqanbaryan/zellij-switch"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + # Nextcloud Apps nextcloud-news = { # https://github.com/nextcloud/news/releases diff --git a/lib/default.nix b/lib/default.nix index dc4b03e..bd4f86d 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -66,6 +66,7 @@ lib overlays = [ inputs.nur.overlays.default inputs.nix2vim.overlay + inputs.zellij-switch.overlays.default ] ++ (importOverlays ../overlays); # System types to support. diff --git a/platforms/home-manager/modules/nmasur/presets/programs/ghostty.nix b/platforms/home-manager/modules/nmasur/presets/programs/ghostty.nix index 4f05071..a458b11 100644 --- a/platforms/home-manager/modules/nmasur/presets/programs/ghostty.nix +++ b/platforms/home-manager/modules/nmasur/presets/programs/ghostty.nix @@ -30,6 +30,13 @@ in window-decoration = false; macos-non-native-fullscreen = true; fullscreen = true; + keybind = [ + "super+t=unbind" # Pass super-t to underlying tool (e.g. zellij tabs) + "super+shift+]=unbind" + "super+shift+[=unbind" + "ctrl+tab=unbind" + "ctrl+shift+tab=unbind" + ]; }; themes."gruvbox" = { background = config.theme.colors.base00; diff --git a/platforms/home-manager/modules/nmasur/presets/programs/zellij.nix b/platforms/home-manager/modules/nmasur/presets/programs/zellij.nix index 7179160..3bd42c0 100644 --- a/platforms/home-manager/modules/nmasur/presets/programs/zellij.nix +++ b/platforms/home-manager/modules/nmasur/presets/programs/zellij.nix @@ -1,5 +1,6 @@ { config, + pkgs, lib, ... }: @@ -14,6 +15,43 @@ in config = lib.mkIf cfg.enable { + home.packages = [ pkgs.zellij-switch ]; + + programs.fish = { + functions = { + zellij-session = { + # description = "Open a session in Zellij"; + body = # fish + '' + zoxide query --interactive | xargs -I {} sh -c 'zellij pipe --plugin file:$(which zellij-switch.wasm) -- "--cwd {} --layout default --session $(basename {})"' \\; + ''; + }; + }; + }; + + xdg.configFile."zellij/layouts/compact-top.kdl".text = # kdl + '' + layout { + pane size=1 borderless=true { + plugin location="compact-bar" + } + pane + } + ''; + + xdg.configFile."zellij/layouts/default.kdl".text = # kdl + '' + layout { + pane size=1 borderless=true { + plugin location="tab-bar" + } + pane + pane size=1 borderless=true { + plugin location="status-bar" + } + } + ''; + programs.zellij = { enable = true; @@ -22,8 +60,11 @@ in enableZshIntegration = true; settings = { + # default_layout = "compact-top"; # Remove border pane_frames = false; + # Scrollback + scrollback_editor = config.home.sessionVariables.EDITOR; keybinds = { # _props = { # clear-defaults = true; @@ -37,6 +78,7 @@ in "Ctrl p" "Ctrl q" "Ctrl s" + "Alt i" ]; }; normal = { @@ -67,7 +109,7 @@ in }; "bind \"Alt k\"" = { SwitchToMode = { - _args = [ "search" ]; + _args = [ "scroll" ]; }; }; "bind \"Alt o\"" = { @@ -78,6 +120,41 @@ in "bind \"Alt q\"" = { "Quit" = { }; }; + "bind \"Alt Shift p\"" = { + "Run" = { + _args = [ + "${pkgs.fish}/bin/fish" + "-c" + "zellij-session" + ]; + close_on_exit = true; + }; + }; + "bind \"Super t\"" = { + "NewTab" = { }; + }; + "bind \"Super Shift ]\"" = { + "GoToPreviousTab" = { }; + }; + "bind \"Super Shift [\"" = { + "GoToNextTab" = { }; + }; + "bind \"Ctrl Tab\"" = { + "GoToNextTab" = { }; + }; + "bind \"Ctrl Shift Tab\"" = { + "GoToPreviousTab" = { }; + }; + "bind \"Alt Shift i\"" = { + "MoveTab" = { + _args = [ "Left" ]; + }; + }; + "bind \"Alt Shift o\"" = { + "MoveTab" = { + _args = [ "Right" ]; + }; + }; }; locked = { "bind \"Alt l\"" = { @@ -86,6 +163,11 @@ in }; }; }; + session = { + unbind = { + _args = [ "Alt o" ]; + }; + }; }; theme = "custom"; diff --git a/platforms/home-manager/modules/nmasur/profiles/darwin-base.nix b/platforms/home-manager/modules/nmasur/profiles/darwin-base.nix index 78d4090..844d2fc 100644 --- a/platforms/home-manager/modules/nmasur/profiles/darwin-base.nix +++ b/platforms/home-manager/modules/nmasur/profiles/darwin-base.nix @@ -31,6 +31,8 @@ in # Used for aerc xdg.enable = lib.mkDefault pkgs.stdenv.isDarwin; + programs.fish.shellAbbrs.t = "trash"; + # Add homebrew paths to CLI path home.sessionPath = [ "/opt/homebrew/bin/" diff --git a/platforms/home-manager/modules/nmasur/profiles/experimental.nix b/platforms/home-manager/modules/nmasur/profiles/experimental.nix index 7feb540..649e40d 100644 --- a/platforms/home-manager/modules/nmasur/profiles/experimental.nix +++ b/platforms/home-manager/modules/nmasur/profiles/experimental.nix @@ -31,6 +31,8 @@ in pkgs.charm # Manage account and filesystem pkgs.pop # Send emails from a TUI + pkgs.yazi # TUI file explorer + ]; programs.gh-dash.enable = lib.mkDefault true; diff --git a/platforms/home-manager/modules/nmasur/profiles/power-user.nix b/platforms/home-manager/modules/nmasur/profiles/power-user.nix index 8c9e8a6..69911b7 100644 --- a/platforms/home-manager/modules/nmasur/profiles/power-user.nix +++ b/platforms/home-manager/modules/nmasur/profiles/power-user.nix @@ -15,25 +15,26 @@ in home.packages = [ pkgs.age # Encryption pkgs.bc # Calculator + pkgs.bottom # System monitor (top) pkgs.delta # Fancy diffs pkgs.difftastic # Other fancy diffs + pkgs.doggo # DNS client (dig) + pkgs.du-dust # Disk usage tree (ncdu) + pkgs.dua # File sizes (du) + pkgs.duf # Basic disk information (df) pkgs.jless # JSON viewer pkgs.jo # JSON output + pkgs.mpd # TUI slideshows + pkgs.nmasur.jqr # FZF fq JSON tool pkgs.nmasur.osc # Clipboard over SSH - pkgs.qrencode # Generate qr codes pkgs.nmasur.ren-find # Rename files pkgs.nmasur.rep-grep # Replace text in files + pkgs.pandoc # Convert text documents + pkgs.qrencode # Generate qr codes pkgs.spacer # Output lines in terminal pkgs.tealdeer # Cheatsheets + pkgs.tree # Print tree in terminal pkgs.vimv-rs # Batch rename files - pkgs.dua # File sizes (du) - pkgs.du-dust # Disk usage tree (ncdu) - pkgs.duf # Basic disk information (df) - pkgs.pandoc # Convert text documents - pkgs.mpd # TUI slideshows - pkgs.doggo # DNS client (dig) - pkgs.bottom # System monitor (top) - pkgs.nmasur.jqr # FZF fq JSON tool ]; programs.fish.shellAliases = {