diff --git a/README.md b/README.md index ff02745..9f04e86 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) +- [Zellij](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..2c3a849 --- /dev/null +++ b/lua/Navigator/mux/zellij.lua @@ -0,0 +1,55 @@ +---@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. +---@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!') + local U = require('Navigator.utils') + + ---@type Zellij + local state = { + execute = function(arg) + local cmd = string.format('zellij action %s', arg) + return U.execute(cmd) + end, + direction = { + p = 'focus-previous-pane', + h = 'move-focus left', + k = 'move-focus up', + l = 'move-focus right', + j = 'move-focus down' + }, + } + 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..b08c034 100644 --- a/lua/Navigator/navigate.lua +++ b/lua/Navigator/navigate.lua @@ -19,12 +19,21 @@ local function load_mux() if ok_tmux then return tmux end + + local ok_zellij, zellij = pcall(function() + return require('Navigator.mux.zellij'):new() + end) + if ok_zellij then + return zellij + end + local ok_wezterm, wezterm = pcall(function() return require('Navigator.mux.wezterm'):new() end) if ok_wezterm then return wezterm end + return require('Navigator.mux.vi'):new() end