feat: initial version
This commit is contained in:
5 files changed
+234
No files matched your search
+11
@@ -0,0 +1,11 @@
|
||||
image: alpine/edge
|
||||
secrets:
|
||||
- 88cce185-d2ec-4573-9546-e33f36f79bbf
|
||||
sources:
|
||||
- git+ssh://git@git.sr.ht/~swaits/lazyjj.nvim
|
||||
tasks:
|
||||
- mirror-to-github: |
|
||||
cd ~/lazyjj.nvim
|
||||
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
|
||||
git remote add github git@github.com:swaits/lazyjj.nvim.git
|
||||
git push --mirror github
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 Stephen Waits <steve@waits.net>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,69 @@
|
||||
# lazyjj.nvim
|
||||
|
||||
A Neovim plugin that provides a floating window interface for
|
||||
[lazyjj](https://github.com/Cretezy/lazyjj).
|
||||
|
||||
## Requirements
|
||||
|
||||
- Neovim >= 0.5.0
|
||||
- [plenary.nvim](https://github.com/nvim-lua/plenary.nvim)
|
||||
- [lazyjj](https://github.com/Cretezy/lazyjj) installed and available in your PATH
|
||||
|
||||
## Installation
|
||||
|
||||
Using [packer.nvim](https://github.com/wbthomason/packer.nvim):
|
||||
|
||||
```lua
|
||||
use {
|
||||
'swaits/lazyjj.nvim',
|
||||
requires = 'nvim-lua/plenary.nvim',
|
||||
config = function()
|
||||
require('lazyjj').setup()
|
||||
end
|
||||
}
|
||||
```
|
||||
|
||||
Using [lazy.nvim](https://github.com/folke/lazy.nvim):
|
||||
|
||||
```lua
|
||||
{
|
||||
'swaits/lazyjj.nvim',
|
||||
dependencies = 'nvim-lua/plenary.nvim',
|
||||
opts = {}
|
||||
}
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
The plugin can be configured by passing options to the setup function:
|
||||
|
||||
```lua
|
||||
require('lazyjj').setup({
|
||||
mapping = '<leader>jj' -- Change the default keymap
|
||||
})
|
||||
```
|
||||
|
||||
Or when using [lazy.nvim](https://github.com/folke/lazy.nvim):
|
||||
|
||||
```lua
|
||||
{
|
||||
'swaits/lazyjj.nvim',
|
||||
dependencies = 'nvim-lua/plenary.nvim',
|
||||
opts = {
|
||||
mapping = '<leader>jj'
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
- Use the configured keymap (default: `<leader>jj`) to open `lazyjj` in a floating
|
||||
window
|
||||
- Or use the `:LazyJJ` command
|
||||
- Press `q` or lose focus to close the window
|
||||
- The window will automatically return focus to your previous window when
|
||||
closing `lazyjj`
|
||||
|
||||
## License
|
||||
|
||||
This plugin is licensed under the [MIT license](LICENSE).
|
||||
@@ -0,0 +1,30 @@
|
||||
local M = {}
|
||||
|
||||
local health = vim.health or require("health")
|
||||
|
||||
function M.check()
|
||||
-- Start health check
|
||||
health.start("lazyjj.nvim")
|
||||
|
||||
-- Check for required plugins
|
||||
if pcall(require, "plenary") then
|
||||
health.ok("plenary.nvim installed")
|
||||
else
|
||||
health.error("plenary.nvim not installed", {
|
||||
"Install plenary.nvim",
|
||||
"https://github.com/nvim-lua/plenary.nvim",
|
||||
})
|
||||
end
|
||||
|
||||
-- Check for lazyjj executable
|
||||
if vim.fn.executable("lazyjj") == 1 then
|
||||
health.ok("lazyjj executable found in PATH")
|
||||
else
|
||||
health.error("lazyjj executable not found", {
|
||||
"Install lazyjj",
|
||||
"Ensure lazyjj is in your PATH",
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,103 @@
|
||||
-- File: lua/lazyjj/init.lua
|
||||
|
||||
local M = {}
|
||||
|
||||
local function open_floating_window()
|
||||
-- Get plenary's float window module which handles window creation
|
||||
local plenary = require("plenary.window.float")
|
||||
|
||||
-- Create centered floating window at 90% of screen size with rounded borders
|
||||
local win = plenary.percentage_range_window(0.9, 0.8, {
|
||||
border = {
|
||||
"╭",
|
||||
"─",
|
||||
"╮",
|
||||
"│",
|
||||
"│",
|
||||
"╰",
|
||||
"─",
|
||||
"╯",
|
||||
},
|
||||
})
|
||||
|
||||
-- Set buffer filetype for syntax highlighting
|
||||
vim.bo[win.bufnr].filetype = "lazyjj"
|
||||
|
||||
-- Ensure window is completely opaque
|
||||
vim.wo[win.win_id].winblend = 0
|
||||
|
||||
-- Hide buffer when window closes rather than delete it
|
||||
vim.cmd("setlocal bufhidden=hide")
|
||||
|
||||
-- Automatically hide window when focus is lost
|
||||
vim.api.nvim_create_autocmd("WinLeave", {
|
||||
buffer = win.bufnr,
|
||||
callback = function()
|
||||
vim.cmd("hide")
|
||||
end,
|
||||
once = true,
|
||||
})
|
||||
|
||||
-- Return window and buffer handles for further manipulation if needed
|
||||
return win.win_id, win.bufnr
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
-- Store user config for later use
|
||||
M.config = vim.tbl_deep_extend("force", {
|
||||
-- Default configuration options can go here
|
||||
mapping = "<leader>jj", -- Default keymapping
|
||||
}, opts or {})
|
||||
|
||||
-- Create user command
|
||||
vim.api.nvim_create_user_command("LazyJJ", M.open, {})
|
||||
|
||||
-- Set up keymapping if provided
|
||||
if M.config.mapping then
|
||||
vim.keymap.set("n", M.config.mapping, M.open, {
|
||||
noremap = true,
|
||||
silent = true,
|
||||
desc = "LazyJJ", -- This will work with WhichKey and similar plugins
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
function M.open()
|
||||
-- Store current window ID for late -- Check if lazyjj is available
|
||||
local cmd = "lazyjj"
|
||||
if vim.fn.executable(cmd) ~= 1 then
|
||||
vim.notify(
|
||||
"lazyjj executable not found. Please install lazyjj and ensure it's in your PATH.",
|
||||
vim.log.levels.ERROR
|
||||
)
|
||||
return
|
||||
end
|
||||
|
||||
local prev_win = vim.api.nvim_get_current_win()
|
||||
|
||||
-- Create floating window
|
||||
open_floating_window()
|
||||
|
||||
-- Execute lazyjj in the floating window
|
||||
vim.fn.termopen(cmd, {
|
||||
-- Return to previous window on exit
|
||||
on_exit = function()
|
||||
if vim.api.nvim_win_is_valid(prev_win) then
|
||||
vim.api.nvim_set_current_win(prev_win)
|
||||
end
|
||||
end,
|
||||
-- Handle potential errors
|
||||
on_stderr = function(_, data)
|
||||
for _, line in ipairs(data) do
|
||||
if line:match("^Error:.*") then
|
||||
vim.notify("lazyjj error: " .. line, vim.log.levels.ERROR)
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
-- Enter insert mode to allow immediate interaction
|
||||
vim.cmd("startinsert")
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in new issue
Block a user