Skip to content

Commit

Permalink
feat: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
GR3YH4TT3R93 committed Jul 6, 2024
0 parents commit aaca007
Show file tree
Hide file tree
Showing 9 changed files with 957 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .stylua.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
indent_type = "Spaces"
indent_width = 2
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

82 changes: 82 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# zellij-nav.nvim 🖥️

A Lua rewrite of the [`zellij.vim`](https://github.com/fresh2dev/zellij.vim) plugin, enabling seamless integration between Neovim and the Zellij terminal multiplexer.

## Features ✨

- 📂 Open new Zellij panes and tabs from within Neovim.
- 🔄 Navigate between Neovim and Zellij seamlessly.
- ⚙️ Execute Zellij commands directly from Neovim.

## Installation 📦

Use the [lazy.nvim](https://github.com/folke/lazy.nvim) plugin manager to install `zellij-nav.nvim`.

```lua
{
"GR3YH4TT3R93/zellij-nav.nvim",
config = function()
require("zellij-nav").setup({
-- Configuration options go here
})
end
}
```

## Requirements 🛠️

- Neovim 0.10.0 or later. (soft req haven't tested on earlier versions)
- Zellij 0.40.1 or later. (soft req haven't tested on earlier versions)

## Usage 🚀

### Commands

#### Navigation Commands

- `:ZellijNavigateUp` - Move up one Vim window or Zellij pane.
- `:ZellijNavigateDown` - Move down one Vim window or Zellij pane.
- `:ZellijNavigateLeft` - Move left one Vim window or Zellij pane.
- `:ZellijNavigateRight` - Move right one Vim window or Zellij pane.

#### Pane Commands

- `:ZellijNewPane` - Open a floating Zellij pane.
- `:ZellijNewPaneSplit` - Open a Zellij pane below.
- `:ZellijNewPaneVSplit` - Open a Zellij pane to the right.

### Default Keybindings ⌨️

These are the default keybindings set by the plugin:

```lua
vim.keymap.set("n", "<Leader>zk", ":ZellijNavigateUp<CR>", { silent = true })
vim.keymap.set("n", "<Leader>zj", ":ZellijNavigateDown<CR>", { silent = true })
vim.keymap.set("n", "<Leader>zh", ":ZellijNavigateLeft<CR>", { silent = true })
vim.keymap.set("n", "<Leader>zl", ":ZellijNavigateRight<CR>", { silent = true })
vim.keymap.set("n", "<Leader>zn", ":ZellijNewPane<CR>", { silent = true })
vim.keymap.set("n", "<Leader>zs", ":ZellijNewPaneSplit<CR>", { silent = true })
vim.keymap.set("n", "<Leader>zv", ":ZellijNewPaneVSplit<CR>", { silent = true })
```

### Custom Keybindings ⌨️

You can set up your custom keybindings in your `init.lua` file:

```lua
vim.keymap.set("n", "<C-k>", ":ZellijNavigateUp<CR>", { noremap = true, silent = true })
vim.keymap.set("n", "<C-j>", ":ZellijNavigateDown<CR>", { noremap = true, silent = true })
vim.keymap.set("n", "<C-h>", ":ZellijNavigateLeft<CR>", { noremap = true, silent = true })
vim.keymap.set("n", "<C-l>", ":ZellijNavigateRight<CR>", { noremap = true, silent = true })
vim.keymap.set("n", "<C-n>", ":ZellijNewPane<CR>", { noremap = true, silent = true })
vim.keymap.set("n", "<C-s>", ":ZellijNewPaneSplit<CR>", { noremap = true, silent = true })
vim.keymap.set("n", "<C-v>", ":ZellijNewPaneVSplit<CR>", { noremap = true, silent = true })
```

## Contributing ♻️

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

## License 📜

This project is licensed under the GPLv3 License. See the [LICENSE](LICENSE) file for details.
51 changes: 51 additions & 0 deletions lua/zellij-nav/commands.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
local M = {}

function M.commands()
-- User commands
vim.api.nvim_create_user_command("ZellijNavigateUp", function()
require("zellij-nav").zellij_nav_up()
end, {})
vim.api.nvim_create_user_command("ZellijNavigateDown", function()
require("zellij-nav").zellij_nav_down()
end, {})
vim.api.nvim_create_user_command("ZellijNavigateLeft", function()
require("zellij-nav").zellij_nav_left()
end, {})
vim.api.nvim_create_user_command("ZellijNavigateRight", function()
require("zellij-nav").zellij_nav_right()
end, {})

-- Lock and unlock zellij
vim.api.nvim_create_user_command("ZellijLock", function()
require("zellij-nav").zellij_lock()
end, { force = true })

vim.api.nvim_create_user_command("ZellijUnlock", function()
require("zellij-nav").zellij_unlock()
end, { force = true })

vim.api.nvim_create_user_command("ZellijNewPane", function()
require("zellij-nav").zellij_new_pane()
end, {})
vim.api.nvim_create_user_command("ZellijNewPaneSplit", function()
require("zellij-nav").zellij_new_pane("down")
end, {})
vim.api.nvim_create_user_command("ZellijNewPaneVSplit", function()
require("zellij-nav").zellij_new_pane("right")
end, {})

-- Autocommands
vim.api.nvim_create_autocmd("VimEnter", {
pattern = "*",
command = "ZellijLock",
})

vim.api.nvim_create_autocmd("VimLeavePre", {
pattern = "*",
command = "ZellijUnlock",
})

-- Additional commands can be added as needed
end

return M
51 changes: 51 additions & 0 deletions lua/zellij-nav/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
local M = {}

function M.setup()
local nav = require("zellij-nav.utils").zellij_navigate
function M.zellij_nav_up()
nav("k", "up")
end

function M.zellij_nav_down()
nav("j", "down")
end

function M.zellij_nav_left()
nav("h", "left")
end

function M.zellij_nav_right()
nav("l", "right")
end

function M.zellij_lock()
vim.fn.system("zellij action switch-mode locked")
end

function M.zellij_unlock()
vim.fn.system("zellij action switch-mode normal")
end

function M.zellij_new_pane(direction)
direction = direction or ""
M.zellij_unlock() -- Ensure we are in normal mode
local l_direction
if direction ~= "" then
l_direction = " --direction " .. direction
else
l_direction = " --floating"
end
vim.fn.system(
"zellij action new-pane "
.. l_direction
.. ' --close-on-exit --cwd "'
.. vim.fn.getcwd()
.. '" -- '
.. vim.env.SHELL
)
end
end
require("zellij-nav.commands").commands()
require("zellij-nav.mappings").mappings()

return M
21 changes: 21 additions & 0 deletions lua/zellij-nav/mappings.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
local M = {}

function M.mappings()
-- Check if zellij_navigator_no_default_mappings exists and is equal to 1
if vim.g.zellij_navigator_no_default_mappings and vim.g.zellij_navigator_no_default_mappings == 1 then
return
end

vim.g.zellij_navigator_no_default_mappings = 0

-- Key mappings
vim.api.nvim_set_keymap("n", "<leader>zh", ":ZellijNavigateLeft<CR>", { silent = true })
vim.api.nvim_set_keymap("n", "<leader>zj", ":ZellijNavigateDown<CR>", { silent = true })
vim.api.nvim_set_keymap("n", "<leader>zk", ":ZellijNavigateUp<CR>", { silent = true })
vim.api.nvim_set_keymap("n", "<leader>zl", ":ZellijNavigateRight<CR>", { silent = true })
vim.api.nvim_set_keymap("n", "<leader>zn", ":ZellijNewPane<CR>", { silent = true })
vim.api.nvim_set_keymap("n", "<leader>zs", ":ZellijNewPaneSplit<CR>", { silent = true })
vim.api.nvim_set_keymap("n", "<leader>zv", ":ZellijNewPaneVSplit<CR>", { silent = true })
end

return M
17 changes: 17 additions & 0 deletions lua/zellij-nav/utils.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
local M = {}

function M.zellij_navigate(short_direction, direction)
-- Get current window number
local cur_winnr = vim.fn.winnr()

-- Attempt to switch window using short_direction
vim.cmd("wincmd " .. short_direction)

-- Check if window number changed
if cur_winnr == vim.fn.winnr() then
-- If window didn't switch, use zellij action to move focus
vim.fn.system("zellij action move-focus " .. direction)
end
end

return M
4 changes: 4 additions & 0 deletions selene.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
std="vim"

[lints]
mixed_table="allow"
55 changes: 55 additions & 0 deletions vim.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
[selene]
base = "lua51"
name = "vim"

[vim]
any = true

[[describe.args]]
type = "string"
[[describe.args]]
type = "function"

[[it.args]]
type = "string"
[[it.args]]
type = "function"

[[before_each.args]]
type = "function"
[[after_each.args]]
type = "function"

[assert.is_not]
any = true

[assert.matches]
any = true

[assert.has_error]
any = true

[[assert.equals.args]]
type = "any"
[[assert.equals.args]]
type = "any"
[[assert.equals.args]]
type = "any"
required = false

[[assert.same.args]]
type = "any"
[[assert.same.args]]
type = "any"

[[assert.truthy.args]]
type = "any"

[[assert.falsy.args]]
type = "any"

[[assert.spy.args]]
type = "any"

[[assert.stub.args]]
type = "any"

0 comments on commit aaca007

Please sign in to comment.