Skip to content

Commit 99b44c9

Browse files
committed
add nvim side for zellij, waiting for zellij side
[zellij #967](zellij-org/zellij#967)
1 parent 91d8650 commit 99b44c9

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ vim.keymap.set({'n', 't'}, '<A-p>', '<CMD>NavigatorPrevious<CR>')
5555
5656
- [Tmux](https://github.com/numToStr/Navigator.nvim/wiki/Tmux-Integration)
5757
- [WezTerm](https://github.com/numToStr/Navigator.nvim/wiki/WezTerm-Integration)
58+
- [Zellij](https://github.com/numToStr/Navigator.nvim/wiki/Zellij-Integration)
5859

5960
#### Configuration (optional)
6061

lua/Navigator/mux/zellij.lua

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---@mod navigator.zellij Zellij navigator
2+
---@brief [[
3+
---This module provides navigation and interaction for Zellij, and uses |navigator.vi|
4+
---as a base class. This is used automatically when zellij is detected on host system
5+
---but can also be used to manually override the mux.
6+
---
7+
---@brief ]]
8+
9+
---@private
10+
---@class Zellij: Vi
11+
---@field private direction table<Direction, string>
12+
---@field private execute fun(arg: string): unknown
13+
local Zellij = require('Navigator.mux.vi'):new()
14+
15+
---Creates a new Zellij navigator instance
16+
---@return Zellij
17+
---@usage [[
18+
---local ok, zellij = pcall(function()
19+
--- return require('Navigator.mux.zellij'):new()
20+
---end)
21+
---
22+
---require('Navigator').setup({
23+
--- mux = ok and zellij or 'auto'
24+
---})
25+
---@usage ]]
26+
function Zellij:new()
27+
assert(os.getenv('ZELLIJ'), '[Navigator] Zellij is not running!')
28+
local U = require('Navigator.utils')
29+
30+
---@type Zellij
31+
local state = {
32+
execute = function(arg)
33+
local cmd = string.format('zellij action %s', arg)
34+
return U.execute(cmd)
35+
end,
36+
direction = { h = 'left', k = 'up', l = 'right', j = 'down' },
37+
}
38+
self.__index = self
39+
return setmetatable(state, self)
40+
end
41+
42+
---Switch pane in zellij
43+
---@param direction Direction See |navigator.api.Direction|
44+
---@return Zellij
45+
function Zellij:navigate(direction)
46+
self.execute(string.format('move-focus %s', self.direction[direction]))
47+
return self
48+
end
49+
50+
return Zellij

lua/Navigator/navigate.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,27 @@ local N = {
1313
---Detect and load correct mux
1414
---@return Vi
1515
local function load_mux()
16+
local ok_zellij, zellij = pcall(function()
17+
return require('Navigator.mux.zellij'):new()
18+
end)
19+
if ok_zellij then
20+
return zellij
21+
end
22+
1623
local ok_tmux, tmux = pcall(function()
1724
return require('Navigator.mux.tmux'):new()
1825
end)
1926
if ok_tmux then
2027
return tmux
2128
end
29+
2230
local ok_wezterm, wezterm = pcall(function()
2331
return require('Navigator.mux.wezterm'):new()
2432
end)
2533
if ok_wezterm then
2634
return wezterm
2735
end
36+
2837
return require('Navigator.mux.vi'):new()
2938
end
3039

0 commit comments

Comments
 (0)