From c6d30e3d4890d54d341174091bdc558d29e1fd9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=E1=BA=A7n=20=C4=90=E1=BB=A9c=20Nam?= Date: Sun, 21 Apr 2024 16:16:44 +0700 Subject: [PATCH 1/2] feat: add support for Zellij --- README.md | 1 + lua/Navigator/mux/zellij.lua | 54 ++++++++++++++++++++++++++++++++++++ lua/Navigator/navigate.lua | 6 ++++ 3 files changed, 61 insertions(+) create mode 100644 lua/Navigator/mux/zellij.lua diff --git a/README.md b/README.md index ff02745..ad3d05c 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ vim.keymap.set({'n', 't'}, '', 'NavigatorPrevious') - [Tmux](https://github.com/numToStr/Navigator.nvim/wiki/Tmux-Integration) - [WezTerm](https://github.com/numToStr/Navigator.nvim/wiki/WezTerm-Integration) +- [Zellj](https://github.com/numToStr/Navigator.nvim/wiki/Zellij-Integration) #### Configuration (optional) diff --git a/lua/Navigator/mux/zellij.lua b/lua/Navigator/mux/zellij.lua new file mode 100644 index 0000000..9abc483 --- /dev/null +++ b/lua/Navigator/mux/zellij.lua @@ -0,0 +1,54 @@ +---@mod navigator.zellij Zellij navigator +---@brief [[ +---This module provides navigation and interaction for Zellij, and uses |navigator.vi| +---as a base class. This is used automatically when zellij is detected on host +---system but can also be used to manually override the mux. +---Read also: https://github.com/numToStr/Navigator.nvim/wiki/Zellij-Integration +---@brief ]] + +---@private +---@class Zellij: Vi +---@field private direction table +---@field private execute fun(arg: string): unknown +local Zellij = require('Navigator.mux.vi'):new() + +---Creates a new Zellij navigator instance +---@return Zellij +---@usage [[ +---local ok, zellij = pcall(function() +--- return require('Navigator.mux.zellij'):new() +---end) +--- +---require('Navigator').setup({ +--- mux = ok and zellij or 'auto' +---}) +---@usage ]] +function Zellij:new() + assert(os.getenv('ZELLIJ'), '[Navigator] Zellij is not running!') + + ---@type Zellij + local state = { + execute = function(arg) + return require('Navigator.utils').execute(string.format('zellij action %s', arg)) + end, + direction = { + p = 'focus-previous-pane', + h = 'move-focus-or-tab left', + j = 'move-focus-or-tab down', + k = 'move-focus-or-tab up', + l = 'move-focus-or-tab right', + }, + } + self.__index = self + return setmetatable(state, self) +end + +---Switch pane in zellij +---@param direction Direction See |navigator.api.Direction| +---@return Zellij +function Zellij:navigate(direction) + self.execute(string.format("%s", self.direction[direction])) + return self +end + +return Zellij diff --git a/lua/Navigator/navigate.lua b/lua/Navigator/navigate.lua index 12af69b..7fa6115 100644 --- a/lua/Navigator/navigate.lua +++ b/lua/Navigator/navigate.lua @@ -13,6 +13,12 @@ local N = { ---Detect and load correct mux ---@return Vi local function load_mux() + local ok_zellij, zellij = pcall(function() + return require('Navigator.mux.zellij'):new() + end) + if ok_zellij then + return zellij + end local ok_tmux, tmux = pcall(function() return require('Navigator.mux.tmux'):new() end) From 530e2a9a5215f8d41bb6f249171987716eed1be8 Mon Sep 17 00:00:00 2001 From: Vinh Chuc Date: Tue, 20 Aug 2024 11:29:51 +0100 Subject: [PATCH 2/2] Fix zellij mappings for up/down --- lua/Navigator/mux/zellij.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/Navigator/mux/zellij.lua b/lua/Navigator/mux/zellij.lua index 9abc483..1374ede 100644 --- a/lua/Navigator/mux/zellij.lua +++ b/lua/Navigator/mux/zellij.lua @@ -34,8 +34,8 @@ function Zellij:new() direction = { p = 'focus-previous-pane', h = 'move-focus-or-tab left', - j = 'move-focus-or-tab down', - k = 'move-focus-or-tab up', + j = 'move-focus down', + k = 'move-focus up', l = 'move-focus-or-tab right', }, }