index : neolij.nvim
Seamless Neovim/Zellij integration with built-in navigation, pane/tab management, and Lua scripting.
about summary refs log tree commit diff
author y2w8 <yousefalharby416@gmail.com> 2026-01-29 13:49:22 +0300
committer y2w8 <yousefalharby416@gmail.com> 2026-01-29 13:49:22 +0300
commit 71a2e635b8f265ea9ccd1b47f4b365ce56cac9b0 [patch]
tree fa263d8b8f7ed8138cbf6dbd438cc6b5d2e0fedc
parent 514a5483e40097b2ecbae7c74e272b7838d39665
download 71a2e635b8f265ea9ccd1b47f4b365ce56cac9b0.tar.gz

Remove MODE and format the code

Diffstat

-rw-r--r-- lua/zellij/health.lua 12
-rw-r--r-- lua/zellij/init.lua 205
 2 files changed, 117 insertions(+), 100 deletions(-)

diff --git a/lua/zellij/health.lua b/lua/zellij/health.lua
index 8c76b56..e301f86 100644
--- a/lua/zellij/health.lua
+++ b/lua/zellij/health.lua
@@ -4,21 +4,21 @@

-- Neovim version check
if vim.fn.has("nvim-0.9") == 1 then
  health.ok("Neovim version >= 0.9")
	health.ok("Neovim version >= 0.9")
else
  health.error("Neovim 0.9+ is required")
	health.error("Neovim 0.9+ is required")
end

-- Zellij executable check
if vim.fn.executable("zellij") == 1 then
  health.ok("zellij found in PATH")
	health.ok("zellij found in PATH")
else
  health.error("zellij not found in PATH")
	health.error("zellij not found in PATH")
end

-- check if inside zellij session
if vim.env.ZELLIJ then
  health.ok("Running inside Zellij session")
	health.ok("Running inside Zellij session")
else
  health.warn("Not running inside Zellij (plugin will still load, but actions will fail)")
	health.warn("Not running inside Zellij (plugin will still load, but actions will fail)")
end
diff --git a/lua/zellij/init.lua b/lua/zellij/init.lua
index 8e3908d..9c819e1 100644
--- a/lua/zellij/init.lua
+++ b/lua/zellij/init.lua
@@ -1,138 +1,155 @@
local M = {}

-- Modes
local MODE = {
  WINDOW = "window",
  TAB = "tab",
local direction_translation = {
	up = "k",
	down = "j",
	left = "h",
	right = "l",
}

  local direction_translation = {
    up = "k",
    down = "j",
    left = "h",
    right = "l",
  }
-- Run zellij action safely
function M.zellij_action(args)
  vim.fn.system("zellij action " .. args)
  if vim.v.shell_error ~= 0 then
    error("zellij executable not found in PATH")
  end
	vim.fn.system("zellij action " .. args)
	if vim.v.shell_error ~= 0 then
		error("zellij executable not found in PATH")
	end
end

-- Try vim window move, fallback to zellij
local function navigate(direction, vim_key, fallback)
  local before = vim.fn.winnr()
  vim.cmd("wincmd " .. vim_key)
  local after = vim.fn.winnr()

  -- If vim didn't move, fallback to zellij
  if before == after then
    M.zellij_action(fallback .. " " .. direction)
  end
	local before = vim.fn.winnr()
	vim.cmd("wincmd " .. vim_key)
	local after = vim.fn.winnr()

	-- If vim didn't move, fallback to zellij
	if before == after then
		M.zellij_action(fallback .. " " .. direction)
	end
end

-- Window navigation
function M.move(direction)
  navigate(direction, direction_translation[direction], "move-focus")
	navigate(direction, direction_translation[direction], "move-focus")
end

-- Window navigation or tab switch
function M.move_or_tab(direction)
  navigate(direction, direction_translation[direction], "move-focus-or-tab")
	navigate(direction, direction_translation[direction], "move-focus-or-tab")
end

-- Tab actions
function M.new_tab(opts)
  if type(opts) == "table" then
    opts = opts.args
  end

  if opts ~= "" then
    M.zellij_action("new-tab " .. opts)
  else
    M.zellij_action("new-tab")
  end
	if type(opts) == "table" then
		opts = opts.args
	end

	if opts ~= "" then
		M.zellij_action("new-tab " .. opts)
	else
		M.zellij_action("new-tab")
	end
end

function M.rename_tab(name)
  if type(name) == "table" then
    name = name.args
  end

  if name == "" or name == nil then
    name = vim.fn.input("Tab name: ")
  end

  if name == nil or name == "" then
    vim.notify("No tab name provided", vim.log.levels.ERROR)
    return
  end

  M.zellij_action("rename-tab " .. name)
	if type(name) == "table" then
		name = name.args
	end

	if name == "" or name == nil then
		name = vim.fn.input("Tab name: ")
	end

	if name == nil or name == "" then
		vim.notify("No tab name provided", vim.log.levels.ERROR)
		return
	end

	M.zellij_action("rename-tab " .. name)
end

function M.move_tab(direction)
  M.zellij_action("move-tab " .. direction)
	M.zellij_action("move-tab " .. direction)
end

-- Pane actions
function M.new_pane(opts)
  if type(opts) == "table" then
    opts = opts.args
  end

  if opts ~= "" then
    -- allow custom flags like -d right, -n name, etc
    M.zellij_action("new-pane " .. opts)
  else
    M.zellij_action("new-pane")
  end
	if type(opts) == "table" then
		opts = opts.args
	end

	if opts ~= "" then
		-- allow custom flags like -d right, -n name, etc
		M.zellij_action("new-pane " .. opts)
	else
		M.zellij_action("new-pane")
	end
end

function M.rename_pane(name)
    if type(name) == "table" then
    name = name.args
  end

  if name == "" or name == nil then
    name = vim.fn.input("Pane name: ")
  end

  if name == nil or name == "" then
    vim.notify("No pane name provided", vim.log.levels.ERROR)
    return
  end

  M.zellij_action("rename-pane " .. name)
	if type(name) == "table" then
		name = name.args
	end

	if name == "" or name == nil then
		name = vim.fn.input("Pane name: ")
	end

	if name == nil or name == "" then
		vim.notify("No pane name provided", vim.log.levels.ERROR)
		return
	end

	M.zellij_action("rename-pane " .. name)
end

function M.move_pane(direction)
  M.zellij_action("move-pane " .. direction)
	M.zellij_action("move-pane " .. direction)
end

-- Setup user commands
function M.setup()
  vim.api.nvim_create_user_command("ZellijUp", function() M.move("up") end, {})
  vim.api.nvim_create_user_command("ZellijDown", function() M.move("down") end, {})
  vim.api.nvim_create_user_command("ZellijLeft", function() M.move("left") end, {})
  vim.api.nvim_create_user_command("ZellijRight", function() M.move("right") end, {})

  vim.api.nvim_create_user_command("ZellijLeftTab", function() M.move_or_tab("left") end, {})
  vim.api.nvim_create_user_command("ZellijRightTab", function() M.move_or_tab("right") end, {})

  vim.api.nvim_create_user_command("ZellijNewTab", M.new_tab, { nargs = "*" })
  vim.api.nvim_create_user_command("ZellijRenameTab", M.rename_tab, { nargs = "?" })
  vim.api.nvim_create_user_command("ZellijMoveTabRight", function() M.move_tab("right") end, {})
  vim.api.nvim_create_user_command("ZellijMoveTabLeft", function() M.move_tab("left") end, {})

  vim.api.nvim_create_user_command("ZellijNewPane", M.new_pane, { nargs = "*" })
  vim.api.nvim_create_user_command("ZellijRenamePane", M.rename_pane, { nargs = "?" })
  vim.api.nvim_create_user_command("ZellijMovePaneUp", function() M.move_pane("up") end, {})
  vim.api.nvim_create_user_command("ZellijMovePaneDown", function() M.move_pane("down") end, {})
  vim.api.nvim_create_user_command("ZellijMovePaneRight", function() M.move_pane("right") end, {})
  vim.api.nvim_create_user_command("ZellijMovePaneLeft", function() M.move_pane("left") end, {})

	vim.api.nvim_create_user_command("ZellijUp", function()
		M.move("up")
	end, {})
	vim.api.nvim_create_user_command("ZellijDown", function()
		M.move("down")
	end, {})
	vim.api.nvim_create_user_command("ZellijLeft", function()
		M.move("left")
	end, {})
	vim.api.nvim_create_user_command("ZellijRight", function()
		M.move("right")
	end, {})

	vim.api.nvim_create_user_command("ZellijLeftTab", function()
		M.move_or_tab("left")
	end, {})
	vim.api.nvim_create_user_command("ZellijRightTab", function()
		M.move_or_tab("right")
	end, {})

	vim.api.nvim_create_user_command("ZellijNewTab", M.new_tab, { nargs = "*" })
	vim.api.nvim_create_user_command("ZellijRenameTab", M.rename_tab, { nargs = "?" })
	vim.api.nvim_create_user_command("ZellijMoveTabRight", function()
		M.move_tab("right")
	end, {})
	vim.api.nvim_create_user_command("ZellijMoveTabLeft", function()
		M.move_tab("left")
	end, {})

	vim.api.nvim_create_user_command("ZellijNewPane", M.new_pane, { nargs = "*" })
	vim.api.nvim_create_user_command("ZellijRenamePane", M.rename_pane, { nargs = "?" })
	vim.api.nvim_create_user_command("ZellijMovePaneUp", function()
		M.move_pane("up")
	end, {})
	vim.api.nvim_create_user_command("ZellijMovePaneDown", function()
		M.move_pane("down")
	end, {})
	vim.api.nvim_create_user_command("ZellijMovePaneRight", function()
		M.move_pane("right")
	end, {})
	vim.api.nvim_create_user_command("ZellijMovePaneLeft", function()
		M.move_pane("left")
	end, {})
end

return M