-
-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathzellij.lua
More file actions
54 lines (49 loc) · 1.6 KB
/
zellij.lua
File metadata and controls
54 lines (49 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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<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!')
---@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 down',
k = 'move-focus 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