Skip to content

Commit

Permalink
add nvim side for zellij, waiting for zellij side
Browse files Browse the repository at this point in the history
[zellij #967](zellij-org/zellij#967)
  • Loading branch information
casonadams committed Mar 9, 2023
1 parent 91d8650 commit 99b44c9
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ vim.keymap.set({'n', 't'}, '<A-p>', '<CMD>NavigatorPrevious<CR>')
- [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)

Expand Down
50 changes: 50 additions & 0 deletions lua/Navigator/mux/zellij.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---@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<Direction, string>
---@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 = { h = 'left', k = 'up', l = 'right', j = '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('move-focus %s', self.direction[direction]))
return self
end

return Zellij
9 changes: 9 additions & 0 deletions lua/Navigator/navigate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,27 @@ 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)
if ok_tmux then
return tmux
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

Expand Down

0 comments on commit 99b44c9

Please sign in to comment.